TL; DR
ZonedDateTime.parse( "Jun 13 2003 23:11:52.454 UTC" , DateTimeFormatter.ofPattern ( "MMM d uuuu HH:mm:ss.SSS z" ) ) .toInstant() .toEpochMilli()
1055545912454
java.time
This answer extends to Lockni's answer .
DateTimeFormatter
First, define a formatting pattern that matches your input string by creating a DateTimeFormatter object.
String input = "Jun 13 2003 23:11:52.454 UTC"; DateTimeFormatter f = DateTimeFormatter.ofPattern ( "MMM d uuuu HH:mm:ss.SSS z" );
ZonedDateTime
Parse the string as ZonedDateTime . You can view this class as: ( Instant + ZoneId ).
ZonedDateTime zdt = ZonedDateTime.parse ( "Jun 13 2003 23:11:52.454 UTC" , f );
zdt.toString (): 2003-06-13T23: 11: 52.454Z [UTC]
Count-out era
I do not recommend tracking date-time values ββas count-from- epoch . This makes debugging difficult, as people cannot recognize a significant date-time from a number, so invalid / unexpected values ββcan slip through. In addition, such calculations are ambiguous, in granularity (whole seconds, milli, micro, nano, etc.) and in the era (at least two dozen different computer systems).
But if you insist, you can get a millisecond score from the era of the first moment of 1970 in UTC ( 1970-01-01T00:00:00 ) through Instant . Remember that this means data loss when you truncate any nanoseconds to milliseconds.
Instant instant = zdt.toInstant ();
instant.toString (): 2003-06-13T23: 11: 52.454Z
long millisSinceEpoch = instant.toEpochMilli() ;
1055545912454
About java.time
The java.time framework is built into Java 8 and later. These classes supersede the nasty old time classes such as java.util.Date , .Calendar and java.text.SimpleDateFormat .
The Joda-Time project, now in maintenance mode , advises switching to java.time.
To learn more, see the Oracle Tutorial . And search for qaru for many examples and explanations.
Most of the functionality of java.time is ported to Java 6 and 7 in ThreeTen-Backport and further adapted to Android in ThreeTenABP (see How to use ... ).
The ThreeTen-Extra project extends java.time with additional classes. This project is a proof of possible future additions to java.time. Here you can find useful classes such as Interval , YearWeek , YearQuarter and more .