【发布时间】:2017-03-20 10:50:27
【问题描述】:
我有一个字符串09:28.,我想将此字符串转换为Timestamp 对象。
下面是我的代码:
Object d = getMappedObjectValue(reportBeamDataMap, ReportBeamConstant.DAT_STOPDATE);
Date stopDate1 = (Date)d;
SimpleDateFormat printFormat = new SimpleDateFormat("hh:mm");
String timeString = printFormat.format(stopDate1);
现在我想在String 上方作为Timestamp(仅 HH:MM)。该怎么做?
【问题讨论】:
-
为什么不将
stopDate1转换为TimeStamp而不是timeString? -
因为 stopDate1 也有日期和其他时间数据。我只想要 HH:MM。所以我先把它们串起来。但没关系,对象 d1 = getMappedObjectValue(reportBeamDataMap, ReportBeamConstant.DAT_STOPDATE);日期 stopDate12 = (日期)d1; SimpleDateFormat printFormat1 = new SimpleDateFormat("hh:mm");字符串 timeString1 = printFormat.format(stopDate1);时间戳 tm1 = new Timestamp(printFormat1.parse(timeString1).getTime());这工作得很好。谢谢
标签: java string date datetime timestamp