简体   繁体   English

将java.util.GregorianCalendar.toString()重新转换回GregorianCalendar

[英]Reconvert java.util.GregorianCalendar.toString() back to GregorianCalendar

I am working with CMIS and Java, i loaded all properties from a document and wrote them into an xml file. 我正在使用CMIS和Java,我从文档中加载了所有属性并将它们写入xml文件。

I use Object.toString() method to create text nodes in xml file. 我使用Object.toString()方法在xml文件中创建文本节点。 Therefore i used .toString() method to stringify GregorianCalendar method and it created an output like this 因此,我使用.toString()方法对GregorianCalendar方法进行字符串化,并创建了这样的输出

java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=?,YEAR=2008,MONTH=7,WEEK_OF_YEAR=?,WEEK_OF_MONTH=?,DAY_OF_MONTH=18,DAY_OF_YEAR=?,DAY_OF_WEEK=?,DAY_OF_WEEK_IN_MONTH=?,AM_PM=?,HOUR=?,HOUR_OF_DAY=12,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=?,DST_OFFSET=?]

I need to parse this string back to java.util.GregorianCalendar Object. 我需要将此字符串解析回java.util.GregorianCalendar对象。

Can you help me to solve this big problem? 你能帮我解决这个大问题吗?

Thank you. 谢谢。

If you can modify the node representation, I'd suggest a much easier way: use 如果你可以修改节点表示,我建议一个更简单的方法:使用

Calendar.getTimeInMillis()

instead of toString(). 而不是toString()。 It will give you back the timestamp. 它会返回时间戳。 Then, to convert it back, you can use: 然后,要将其转换回来,您可以使用:

Calendar.getInstance().setTimeInMillis(Long.parseLong(yourMillis))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM