将日期格式转换为不同的日期格式,如 edm

2024-01-27

我有字段类型 java.util.date 并从中获取 to.string() 的值 Sat Sep 14 00:00:00 IDT 2013 但我需要以不同的格式获取它,即 EDM 格式 就像 2013-09-12T14:00 。 有简单的方法吗?

Thanks!


Use SimpleDateFormat(有一个很好的教程here http://www.xyzws.com/javafaq/how-to-use-simpledateformat-class-formating-parsing-date-and-time/142)。考虑这个例子:

Date date = new Date();
System.out.println(date);

其输出:

2013 年 6 月 24 日星期一 21:46:22(英国夏令时)

要转换为 EDM 格式,请执行以下操作:

String firstPartOfPattern = "yyyy-MM-dd";
String secondPartOfPattern = "HH:mm:ss";
SimpleDateFormat sdf1 = new SimpleDateFormat(firstPartOfPattern);
SimpleDateFormat sdf2 = new SimpleDateFormat(secondPartOfPattern);
String formattedDate = sdf1.format(date) + "T" + sdf2.format(date);

formattedDate现在有以下格式:

2013-06-24T21:46:22

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将日期格式转换为不同的日期格式,如 edm 的相关文章

随机推荐