Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert date format to milliseconds?

Tags:

java

android

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

like image 747
Pattabi Raman Avatar asked Oct 12 '11 05:10

Pattabi Raman


People also ask

How do you convert Date to milliseconds?

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.

How do I convert Date to milliseconds in Excel?

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.

How are milliseconds represented in Date format?

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.

How do you convert timestamps to 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 .


1 Answers

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.

like image 148
Buhake Sindi Avatar answered Sep 29 '22 07:09

Buhake Sindi