[英]String to Date in epoch time Format in Java
我有一個我不認識的格式的字符串:字符串收到:“36872 12月12日15:35”,而此日期的窗口表示是:“12/12/2012 5:35 PM”
所以首先,我猜測日期中有些東西被破壞了。 第二,我希望將此字符串解析為一個紀元時間格式
像這樣的東西:“1355371390142”(實際上是“2012-12-13 06:03:10”)
您可以像這樣格式化Java中的Date
:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.