在纪元时间中的字符串格式在Java中

Ela*_*lad 5 java format time date epoch

我有一个我不认识的格式的字符串:字符串收到:"36872 12月12日15:35",而此日期的窗口表示是:"12/12/2012 5:35 PM"

所以首先,我猜测日期中有些东西被破坏了.第二,我希望将此字符串解析为一个纪元时间格式

像这样的东西:"1355371390142"(实际上是"2012-12-13 06:03:10")

And*_*ios 3

你可以Date像这样在 Java 中格式化 s:

String str = "12/12/2012 5:35 PM"; //Your String containing a date
DateFormat dF = new SimpleDateFormat("dd//MM/yyyy hh:mm a"); // The mask
// 'a' value in the Mask represents AM / PM - h means hours in AM/PM mode
Date date = dF.parse(str); // parsing the String into a Date using the mask

//Date.getTime() method gives you the Long with milliseconds since Epoch.
System.out.println("Epoch representation of this date is: " + date.getTime()); 
Run Code Online (Sandbox Code Playgroud)

请参阅此掩码选项:http://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html