开发者

How to set time on a Date object to be zero (00/00/00)

Calendar calendar = Calendar.getInstance();
calendar.setTi开发者_如何学运维meInMillis(0);

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


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);


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


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜