5

我有一个我不认识的格式的字符串:收到的字符串:“36872 Dec 12 15:35”,而该日期的 Windows 表示是:“12/12/2012 5:35 PM”

所以首先,我猜日期中有些东西被破坏了。其次,我希望将此字符串解析为纪元时间格式

像这样:“1355371390142”(实际上是“2012-12-13 06:03:10”)

4

1 回答 1

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()); 

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

于 2012-12-13T12:59:50.950 回答