How can I set custom Datetime format in XmlDateTime class
Question asked by Edgar Miuler - April 1 at 7:43 AM
Answered
Hello.

I have some DateTime fields in XML therefore I am using XmlDateTime class.

It says that dateTime comprises [-]CCYY-MM-DDThh:mm:ss[.ff][[Z]|[[+|-]hh:mm]] 
However, I need to change that format (I need .fff, not .ff). How can I do that? 
Thanks.

1 Reply

Reply to Thread
0
Liquid Support Replied
Employee Post Marked As Answer
Hi,

XmlDateTime will write out up to 9 fractional second digits, but does not write out trailing 0's as per the XML Schema specification:
https://www.w3.org/TR/xmlschema-2/#dateTime

Section 3.2.7.2 Canonical representation:
- The fractional second string, if present, must not end in '0';

If you want a non-conforming date format then you can simply change the XSD to use an xs:string instead of an xs:dateTime and set whatever value you like. You could also specifying a Pattern facet on the xs:string to restrict valid values.

Reply to Thread