The semantics of xsd: dateTime without a time zone and its conversion to Date

I have a question about the built-in XML schema type xsd:dateTime.

What is the exact semantics xsd:dateTimewithout a time zone? Ex. 1970-01-01T00:00:00.

I read a number of XML Schema specifications, but couldn't find out how to handle it.

In particular, I want to understand how to correctly convert xsd:dateTimeto a Date object (e.g., java.util.Dateor JavaScript Date).

Side note: I know very well Java classes such as DatatypeConverteror DatatypeFactory, I would like to find an XML Schema specification that defines how to do this.

The problem with the class Date(in Java as well as in JavaScript) is that these classes have time intervals (the default for the local time zone). If I get xsd:dateTimewithout a time zone at the entrance, then I need to somehow think about which time zone I should accept. Otherwise, I just cannot convert it to a time value (e.g. Date).

Now the question is what should I accept. Here I see the following options:

  • Suppose something is default, like UTC.
  • Assume the local time zone of the processor.

I do not like the second option. This is completely random! On my machine, if I run

System.out.println(DATATYPE_FACTORY
    .newXMLGregorianCalendar("1970-01-01T00:00:00")
    .toGregorianCalendar().getTime().getTime());

-3600000, 0, 3600000 GMT + 1, GMT GMT-1 ( . , . XML ,

<date-time>1970-01-01T00:00:00</date-time>

, ?

( UTC) , , -, , ( ) Java-.

- - timezoneless xsd:dateTime?

.

Update:

:

  • "" , UTC - . - , - .
  • , , xsd:dateTime Date, - - .
  • , . .
  • , - .

:

  • context, XML ( JAXB JAXBContext). getDefaultTimezoneOffset() setDefaultTimezoneOffset(int timezoneOffset)
  • . 0 (UTC) . (, Java).
  • , ( "" ).
  • xsd:dateTime Date, , context.getDefaultTimezoneOffset().
  • ( ) Date. , originalTimezoneOffset - . Date, (, ).
  • Date originalTimezoneOffset, , .
+4
2

, ; , . :

  • , .

  • UTC

XPath/XQuery/XSLT - . , , .

. , , 21 1973 ? ? , , , , , .

+4

. dateTime spec:

, "" - , ; 14 . ( timeOnTimeline) , next-higher. , 32, 29 02 2002 ( 2002 ).

, 3.2.7.2 dateTime

( ):

P Q [...] A.Normalize P Q. , , Z, Z [...]

:

C. , P , Q - , : 1.P < Q, P < (Q +14: 00) 2.P > Q, P > (Q -14: 00) 3.P < Q , , (Q +14: 00) < P < (Q -14: 00)

. , P , Q - : 1. P < Q, (P -14: 00) Q. 2. P > Q, (P +14: 00) > Q. 3. P < > Q , , (P +14: 00) Q < (P -14: 00)

" " 14, 3.2.7:

[...] , 14 .

, , :

2000-01-01T12: 00: 00 < > 1999-12-31T23: 00: 00Z

2000-01-16T12: 00: 00 < > 2000-01-16T12: 00: 00Z

2000-01-16T00: 00: 00 < > 2000-01-16T12: 00: 00Z

, . , , XML, ! , , , , , , "" .

, , , . . , - ; , XML XSD, .

+2

Source: https://habr.com/ru/post/1532557/


All Articles