473,322 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Serializing DateTime

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.

--
Daniel
Nov 12 '05 #1
3 4113
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

"Daniel Lidström" <so*****@microsoft.com> wrote in message
news:un****************************@40tude.net...
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.

--
Daniel

Nov 12 '05 #2
On Thu, 27 May 2004 12:53:48 +0200, Aleks wrote:
"Daniel Lidström" <so*****@microsoft.com> wrote in message
news:un****************************@40tude.net...
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.
Hi,

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


Thanks for the idea Aleks.

--
Daniel
Nov 12 '05 #3
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.

"Daniel Lidström" <so*****@microsoft.com> wrote in message
news:1b******************************@40tude.net.. .
On Thu, 27 May 2004 12:53:48 +0200, Aleks wrote:
"Daniel Lidström" <so*****@microsoft.com> wrote in message
news:un****************************@40tude.net...
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.

Hi,

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


Thanks for the idea Aleks.

--
Daniel

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Microsoft | last post by:
Hello everyone, I am fairly new to C#, but I have done my fair share of C++ and XML. I am experimenting with C# serialization and I have a nagging problem. I have an XML that looks like this......
4
by: John Vottero | last post by:
When a class contains a TimeSpan property, XmlSerializer doesn't work. A TimeSpan property is serialized like: <MySpan /> I've read a number of posts that talk about why this happens and how...
0
by: | last post by:
I have a class that includes a date. When I serialize it, I need to format the date in a specific way to match an existing schema. The property is not included in the output. What am I doing...
2
by: Earl Teigrob | last post by:
I am saving and restoring value types such as Int32, DateTime and Boolean in strings. I was wondering if there is a mechanism build into .NET for serializing and deserializing these to string...
0
by: William Stacey [MVP] | last post by:
Couple questions. Say we are talking about native types such as int, decimal, long, etc. 1) Does XmlSerializer use Invariant culture to serialize and deserialize number types? 2) If wanted to do...
5
by: Brendan | last post by:
Hi All I can't find the "Python Way" of writing a datetime instance to a string so that it can be easily parsed back again. time.strptime is apparantly not supported on some platforms, and...
0
by: dph5010 | last post by:
I'm trying to make an object that will reflect the response from isbndb.com's API so I can serialize the results into my code. Right now I have code that works, however, the structure isn't quite the...
0
by: Joris van Lier | last post by:
Hi, I'm looking for advice on mapping between different XML Schamata. The C# (2.0) project I'm currently working on needs to send custom business entities to multiple webservices, each accepting...
1
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
Can I serialize a List<T>? I created a Serializable class with integers, strings, and a DateTime. To make it powerful, I used this class to create a List. Visual Studio 2005 Pro will not...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.