本文介绍了将日期格式转换为不同日期格式,如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 formatlike 2013-09-12T14:00 .There is simple way to do that?

谢谢!

推荐答案

使用 SimpleDateFormat (提供了很好的教程此处).考虑以下示例:

Use SimpleDateFormat (a good tutorial is available here). Consider this example:

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

输出:

要转换为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 现在具有以下格式:

这篇关于将日期格式转换为不同日期格式,如edm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 05:33
查看更多