将日期格式转换为不同日期格式,如edm [英] convert date format to diffrent date format like edm
本文介绍了将日期格式转换为不同日期格式,如edm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我具有字段类型java.util.date,并从中获取to.string()的值2013年9月14日星期六00:00:00 IDT,但我需要以EDM格式使用其他格式像2013-09-12T14:00.有简单的方法可以做到吗?
Im having field type java.util.date and from it im getting the value of to.string() Sat Sep 14 00:00:00 IDT 2013 but I need to get it in different format which is EDM format like 2013-09-12T14:00 . There is simple way to do that?
谢谢!
推荐答案
Use SimpleDateFormat
(a good tutorial is available here). Consider this example:
Date date = new Date();
System.out.println(date);
输出:
2013年6月24日星期一21:46:22 BST
Mon Jun 24 21:46:22 BST 2013
要转换为EDM格式,请执行以下操作:
To convert to EDM format, do the following:
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
2013-06-24T21:46:22
这篇关于将日期格式转换为不同日期格式,如edm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文