日期到UTC格式Java
发布时间:2020-12-14 16:19:13 所属栏目:Java 来源:网络整理
导读:我有这样的字符串2013-10-22T01:37:56.我需要将此字符串更改为UTC日期格式,如MM / dd / yyyy KK:mm:ss a.我已经尝试了一些代码,但它没有返回UTC datetime. 我的代码是 String[] time = itsAlarmDttm.split("T"); String aFormatDate = time[0]+ " "+time
我有这样的字符串2013-10-22T01:37:56.我需要将此字符串更改为UTC日期格式,如MM / dd / yyyy KK:mm:ss a.我已经尝试了一些代码,但它没有返回UTC datetime.
我的代码是 String[] time = itsAlarmDttm.split("T"); String aFormatDate = time[0]+ " "+time[1]; String aRevisedDate = null; try { final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); final Date dateObj = sdf.parse(aFormatDate); aRevisedDate = new SimpleDateFormat("MM/dd/yyyy KK:mm:ss a").format(dateObj); System.out.println(aRevisedDate); } catch (ParseException e) { itsLogger.error("Error occured in Parsing the Data Time Object: " +e.getMessage()); } catch (Exception e) { itsLogger.error("Error occured in Data Time Objecct: " +e.getMessage()); } 我得到的输出是MM / dd / yyyy KK:mm:ss a格式.但不是UTC时间格式. 解决方法
尝试使用Z或z时区标记格式化日期:
new SimpleDateFormat("MM/dd/yyyy KK:mm:ss a Z").format(dateObj); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |