Groups | Blog | Home
all groups > dotnet xml > august 2004 >

dotnet xml : Lack of millisecond support in UniversalSortableDateTimePattern


shodson NO[at]SPAM gmail.com
8/5/2004 4:22:46 PM
Why doesn't this date time pattern support milliseconds? That makes
it hard for me to map my date, time, and dateTime XML schema types to
System.DateTime values without losing millisecond precision. The
DateTime.ToString("u") format specifier chops off the milliseconds of
my values

:(

Derek Harmon
8/5/2004 10:01:01 PM
[quoted text, click to view]

UniversalSortableDateTimePattern's purposefully supports the
'u' format specifier to format output. The governing standard is
ISO 8601. That standard states that a conformant date time may
or may not include fractional seconds.

Had 'u' formatted output with milliseconds, it would be producing
a representation of a date time that some ISO 8601 conformant
recipients may not understand, undercutting the interoperability
of the format.

The .NET Framework fully supports custom date/time formats
(i.e., "pictures"). There's nothing to stop you from using,

"yyyy-MM-ddTHH:mm:ss.fff"

as a format specifier.

[quoted text, click to view]

Format specifiers produce textual output; if you are mapping an
xsd:dateTime primitive type value to a CLR DateTime type, then
output isn't what you need.

[quoted text, click to view]

I think System.Globalization is the wrong namespace to look at
for classes to go to/from primitive XML Schema Datatypes. If
you look in the System.Xml namespace, there is an XmlConvert
class that has all the functions you need for translating the
xsd:dateTime and related datatypes.

DateTime dt = XmlConvert.ToDateTime( strDateTimeAttrValueIn);
string strDateTimeAttrValueOut = XmlConvert.ToString( dt);

ToDateTime( ) and ToString( ) both preserve optional milliseconds
and timezone qualifiers that may be present.


Derek Harmon

AddThis Social Bookmark Button