tags:

views:

237

answers:

3
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(0);

This sets it to the deafult value. How do I set it to zero?

A: 

You should probably be aware of what setTimeInMillis() expects:

public void setTimeInMillis(long millis)

Sets this Calendar's current time from the given long value.

Parameters:
millis - the new time in UTC milliseconds from the epoch.

The epoch is defined as:

An instant in time can be represented by a millisecond value that is an offset from the Epoch, January 1, 1970 00:00:00.000 GMT (Gregorian).

matt b
A: 

You can zero-out what value you want using the set method. For example:

calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
dpb
This would keep the month, day, and year as the current month day and year
matt b
I think that's what the OP wants.
David M
The question is "How to set time on a Date object to be zero". Did I misunderstand?
dpb
I want the date to be zero so that when I do a DateFormat, I would get something like 00/00/00 (MM/dd/yy). Thanks.
Milli
If this is just for formatting purposes of display (and since Date can't represent very well the BigBang) you could use null for the date and display 00/00/00 as default when that is null. What exactly are you trying to do?
dpb
+4  A: 

(00/00/00) is not a valid date; the API will not produce this value.

McDowell
Just an example..
Milli
You should use a valid date in your examples.
Steve Kuo