Java 中的 XMLGregorianCalendar,没有时区 [英] XMLGregorianCalendar in java, with NO Timezone

查看:32
本文介绍了Java 中的 XMLGregorianCalendar,没有时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建没有时区的 XMLGregorianCalendar?没有时间偏移 (0) == UTC,它在输出中输出一个Z".my字段的含义是隐式本地时间,在xml记录的其他地方指定locality(比如地址).

How do I create an XMLGregorianCalendar without a timezone? No time offset (0) == UTC which outputs a 'Z' in the output. The meaning of my field is implicit local time, where locality is specified elsewhere on the xml record (such as address).

如何创建具有未定义时区(时区不确定)的 XMLGregorianCalendar?

How do I create an XMLGregorianCalendar with undefined timezone (TimeZone indeterminate)?

有效的 XML ISO-8601 公历格式包括:

Valid XML ISO-8601 Gregorian Calendar formats include:

  • CCYY-MM-DDThh:mm:ss – 没有祖鲁语时间指示符或 TimeOffset 是指相对物理位置的本地时间.
  • CCYY-MM-DDThh:mm:ssZ – 相对物理位置的 DateTime 以 UTC (Zulu) 时间表示,对于本地时间,必须进行转换.
  • CCYY-MM-DDThh:mm:ss+05:30 相对物理位置的 DateTime 以某个时区表示,该时区与 UTC 有 +5 小时 30 分钟的偏差.对于本地时间,我们必须首先转换为 UTC,然后通过偏移 UTC 转换为本地时间.无法保证提供的位置是记录位置的当地时间.

推荐答案

我看了XMLGregorianCalendar 的文档.在顶部的表中,底部的行,它说时区是

I looked at the documentation of XMLGregorianCalendar. In the table at the top, the bottom row, it says that the timezone is

分钟数或DatatypeConstants.FIELD_UNDEFINED.

那么让我们试试后一个选项:

So let’s try the latter option:

    System.out.println(xcal);
    xcal.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
    System.out.println(xcal);

在一次测试运行中打印:

In one test run this printed:

2017-11-30T07:54:05.647+01:00
2017-11-30T07:54:05.647

在我将时区设置为未定义后,它不再打印偏移量.所以我相信我已经得到了你想要的.

After I set the time zone to undefined, it no longer prints the offset. So I believe I have obtained what you want.

这篇关于Java 中的 XMLGregorianCalendar,没有时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆