How to convert date format to milliseconds?

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

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

This beginupd variable contains the format

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

Now, how to convert this format in millisecond to Long datatype? Any help is greatly appreciated and thanks in advance ...

+44
java android
12 Oct '11 at 5:35
source share
4 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.

+80
Oct 12 2018-11-12T00:
source share
 date.setTime(milliseconds); 

this is for given milliseconds in a date

 long milli = date.getTime(); 

This is for getting time in milliseconds.

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

+10
Oct. 12 2018-11-11T00:
source share

you can use

 Calendar cal = Calendar.getInstance(); cal.setTime(beginupd); long millis = cal.getTimeInMillis(); 
+9
12 Oct '11 at 5:40
source share

beginupd.getTime() will give you time in milliseconds from January 1, 1970, 00:00:00 GMT until the time you specify in the Date object

+1
Oct 12 2018-11-11T00:
source share



All Articles