If it is not already a Date
, parse it into a Date
. The date format is arbitrary as long as you can construct an appropriate SimpleDateFormat
to represent it.
After you have a Date
, you can use Date.getTime()
to retrieve the millisecond value.
For the example you have shown, if you have a string:
String datestr = "2014-14-03 01:39:00";
Then the matching SimpleDateFormat
would be:
DateFormat format = new SimpleDateFormat("yyyy-dd-MM HH:mm:ss");
And conversion would be:
long millis = format.parse(datestr).getTime();
It's no problem to use Date
for this, as the constructors and getTime()
are still some of the few remaining non-deprecated components.
Edit: I see that you have edited your question to include the use of Date
. The constructor you are using is deprecated, and is also not very flexible wrt. input (you have to have the date components already parsed to use it). A SimpleDateFormat
provides a non-deprecated way to convert arbitrary strings to dates.