all groups > dotnet xml > may 2004 >
You're in the

dotnet xml

group:

Serializing DateTime


Serializing DateTime Lidström
5/27/2004 10:55:44 AM
dotnet xml:
How do I serialize a DateTime attribute to HH:MM:SS? I've tried this:

[XmlAttributeAttribute(AttributeName="time", DataType="time")]

But it is serialized as time="10:45:34.7031250+02:00". I would like it to
be plainly "10:45:34". I will not be doing any calculations on the time,
just record time of creation.

--
Re: Serializing DateTime Jiho Han
5/27/2004 11:45:38 AM
You can make your field(I assume, is where this attribute is attached to)
into a property and use a ToString of the DateTime to output whatever you
want.

private DateTime _ABC;

[XmlAttributeAttribute(AttributeName="time")]
public string DateTimeAttributeNamedABC
{
get
{
return _ABC.ToString("T");
}
set
{
_ABC = DateTime.Parse(value);
}
}

Something like that. I'm not sure about the setter. You probably need
something better there.

[quoted text, click to view]

Re: Serializing DateTime Aleks
5/27/2004 12:53:48 PM
Hi,

maybe you should try to create a serializable Class where you will put a
reference of your DataTime object.

Aleks,
www.Dotnet-Project.com

[quoted text, click to view]

Re: Serializing DateTime Lidström
5/27/2004 12:56:45 PM
[quoted text, click to view]

Thanks for the idea Aleks.

--
AddThis Social Bookmark Button