gpt4 book ai didi

java - Java 中纪元时间格式的字符串到日期

转载 作者:搜寻专家 更新时间:2023-10-31 20:21:44 24 4
gpt4 key购买 nike

我有一个我不太认识的格式的字符串:收到的字符串:“36872 Dec 12 15:35”而此日期的 Windows 表示是:“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

关于java - Java 中纪元时间格式的字符串到日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13860275/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com