How to get the millisecond time from date? I have the following code.
Date beginupd = new Date(cursor1.getLong(1));
This variable beginupd 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? Any help is highly appreciated and thanks in advance...
This is the number of seconds since the 1970 epoch. To convert seconds to milliseconds, you need to multiply the number of seconds by 1000. To convert a Date to milliseconds, you could just call timeIntervalSince1970 and multiply it by 1000 every time.
Select a timestamp type in the Type group box. If you need to display milliseconds, instead of clicking the Date category, select Custom, and then enter dd-mmm-yyyy hh:mm:ss. 000 in the Type field.
Usually we display time in in 12 hour format hh:mm:aa format (e.g. 12:30 PM) or 24 hour format HH:mm (e.g. 13:30), however sometimes we also want to show the milliseconds in the time. To show the milliseconds in the time we include “SSS” in the pattern which displays the Milliseconds.
A simple solution is to get the timedelta object by finding the difference of the given datetime with Epoch time, i.e., midnight 1 January 1970. To obtain time in milliseconds, you can use the timedelta. total_seconds() * 1000 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With