java MM/dd/yyyy 中的 xmlgregoriancalendar 格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16031903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 21:41:34  来源:igfitidea点击:

xmlgregoriancalendar formatting in MM/dd/yyyy

javaxmldateformatting

提问by stallion

I have a variable of type date in the format MM/dd/yyyy. I need to convert the tempdate to xmlgregoriancalendar type in the same format i.e., MM/dd/yyyy.

我有一个格式为 date 的变量MM/dd/yyyy。我需要将 tempdate 转换为相同格式的 xmlgregoriancalendar 类型,即MM/dd/yyyy.

The default format when created using newxmlgregoriancalendarDate()is yyyy-MM-ddso i am unable to convert it to MM/dd/yyyyformat of type xmlgregoriancalendar

在使用创建的默认格式newxmlgregoriancalendarDate()yyyy-MM-dd让我无法将其转换为MM/dd/yyyy类型的XMLGregorianCalendar的格式

how to acheive this?

如何实现这一目标?

回答by Jon Skeet

XMLGregorianCalendardoesn't really "have" a format - or rather, it's not part of the data in the object, because the XML format for dates/times is specifiedin a particular format. So the request of "I need to convert the tempdate to xmlgregoriancalendar type in the same format i.e., MM/dd/yyyy" makes no sense, really.

XMLGregorianCalendar并没有真正“具有”格式 - 或者更确切地说,它不是对象中数据的一部分,因为日期/时间的 XML 格式是以特定格式指定的。因此,“我需要将临时日期转换为相同格式的 xmlgregoriancalendar 类型,即 MM/dd/yyyy”的请求是没有意义的,真的。

If you want to get a different textual representation as a string, I suggest you use toGregorianCalendar()to get a java.util.Calendar- then you can get the java.util.Dateand use an appropriately constructed SimpleDateFormatto do the formatting.

如果您想获得不同的文本表示作为 string,我建议您使用toGregorianCalendar()get a java.util.Calendar- 然后您可以获取java.util.Date并使用适当构造的SimpleDateFormat进行格式化。