开发者

How to convert date format to milliseconds?

How to get the millisecond time from date? I have the following code.

Date beginupd = new Date(cursor1.getLong(1));

This variable beginup开发者_如何学运维d contains the format

Wed Oct 12 11:55:03 GMT+05:30 2011

Now how to convert this format to the millisecond time in Long datatype?


long millisecond = beginupd.getTime();

Date.getTime() JavaDoc states:

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.


date.setTime(milliseconds);

this is for set milliseconds in date

long milli = date.getTime();

This is for get time in milliseconds.

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT


You could use

Calendar cal = Calendar.getInstance();
cal.setTime(beginupd);
long millis = cal.getTimeInMillis();


beginupd.getTime() will give you time in milliseconds since January 1, 1970, 00:00:00 GMT till the time you have specified in Date object

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜