开发者

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

开发者 https://www.devze.com 2022-12-16 11:50 出处:网络
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 se
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

精彩评论

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

关注公众号