Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a string Date to long millseconds

I have a date inside a string, something like "12-December-2012". How can I convert this into milliseconds (long)?

like image 285
Dawood Ahmed Avatar asked Sep 18 '12 08:09

Dawood Ahmed


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 you convert String dates to milliseconds Kotlin?

In Kotlin, Wed Oct 12 11:55:03 GMT+05:30 2011 long millisecond = beginupd. getTime(); Date.

How do I convert DateTime to long?

The DateTime. ToLongDateString() method in C# is used to convert the value of the current DateTime object to its equivalent long date string representation.


1 Answers

Using SimpleDateFormat

String string_date = "12-December-2012";  SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yyyy"); try {     Date d = f.parse(string_date);     long milliseconds = d.getTime(); } catch (ParseException e) {     e.printStackTrace(); } 
like image 138
Jon Lin Avatar answered Oct 09 '22 11:10

Jon Lin