Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / November 2005

Tip: Looking for answers? Try searching our database.

datetime format in xml

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
param@community.nospam - 08 Nov 2005 15:33 GMT
Hi all, I am consuming a web service on .net client side. I generated the
proxy class and it has a custom object with a few datetime properties. The
problem is when I populate some of those properties, the underlying xml
serializer formats the property as outlined below

2005-11-07T18:34:36.6990563-06:00

The problem is the WS needs it in the following format:-

2005-11-04T08:30:39

Any ideas on how I can control this?

TIA!
Steven Cheng[MSFT] - 09 Nov 2005 06:24 GMT
Hi Param,

Welcome to MSDN newsgroup.
From your description, you're cosuming a certain webservice which will pass
DateTime object in your .NET client app. And you found that the default
serlized datetime output is not quite suit the webservice's actual
requirement, yes?

As for this quesiton, I think it is due to the current .net framework (1.0,
1.1)'s DateTime class's limitation. The current DateTime class is always
persisted as local time format (with TimeZone offset...), also the

2005-11-07T18:34:36.6990563-06:00

output you got is the default xml serlization output. Since we can not
control the underlying xmlserlization of the DateTime class( build-in basic
type), I'd suggest you consider modifying the .NET client proxy code,
change that class property which uesd to be DateTime type to a string type.
Then, we can use the DateTime class's ToString method to perform datetime
formatting which can output many different formats we want, here is the
related msdn reference on DateTime formatting:

#Standard DateTime Format Strings Output Examples
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconstandarddatetimefo
rmatstringsoutputexample.asp?frame=true

Also, another msdn article discussing on the best practice using DateTime
in .net 1.x application:

#Coding Best Practices Using DateTime in the .NET Framework
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
ml/datetimecode.asp

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Signature

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: <param@community.nospam>
| Subject: datetime format in xml
[quoted text clipped - 10 lines]
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.webservices:8304
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
|
[quoted text clipped - 12 lines]
|
| TIA!
param@community.nospam - 09 Nov 2005 14:51 GMT
Does this behavior change in Net 2.0? If so, how?

> Hi Param,
>
[quoted text clipped - 76 lines]
> |
> | TIA!
Steven Cheng[MSFT] - 10 Nov 2005 05:56 GMT
Thanks for your respone Param,

As for .NET 2.0, of course the DateTime type has greatly enchanged. The
.NET 2.0 DateTime class support a DateTimeKind property which help specify
whether the datetime object is representing a local time, UTC time or
unspecified....

So for local and utc time, the default xmlserliazation output will like
below:

local now:

<dateTime>2005-11-10T13:50:52.5979344-08:00</dateTime>

utc now:

<dateTime>2005-11-10T21:50:52.5979344Z</dateTime>

so we can see for UTC time it no longer append the unused TimeZone offset.
However, since the milliseconds is necessary for precise purpose, it is
still appended.  So for you scenario, we should use the DateTime Formatting
flag to manually do the formatting so as to get the output we want.

Thanks,

Steven Cheng
Microsoft Online Support

Signature

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: <param@community.nospam>
| References: <umrT5mH5FHA.3980@TK2MSFTNGP10.phx.gbl>
<aLYkSZP5FHA.832@TK2MSFTNGXA02.phx.gbl>
| Subject: Re: datetime format in xml
| Date: Wed, 9 Nov 2005 08:51:51 -0600
[quoted text clipped - 9 lines]
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.webservices:30825
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
|
[quoted text clipped - 27 lines]
| >
| > #Standard DateTime Format Strings Output Examples

http://msdn.microsoft.com/library/en-us/cpguide/html/cpconstandarddatetimefo
| > rmatstringsoutputexample.asp?frame=true
| >
| > Also, another msdn article discussing on the best practice using DateTime
| > in .net 1.x application:
| >
| > #Coding Best Practices Using DateTime in the .NET Framework

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
| > ml/datetimecode.asp
| >
[quoted text clipped - 41 lines]
| > |
| > | TIA!
Steven Cheng[MSFT] - 14 Nov 2005 14:27 GMT
Hi Param,

Does my further reply helps a little? If there're still anything else we
can help, please feel free to post here.

Thanks,

Steven Cheng
Microsoft Online Support

Signature

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| X-Tomcat-ID: 130864800
| References: <umrT5mH5FHA.3980@TK2MSFTNGP10.phx.gbl>
<aLYkSZP5FHA.832@TK2MSFTNGXA02.phx.gbl>
<#nDaf0T5FHA.2040@TK2MSFTNGP14.phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain
[quoted text clipped - 9 lines]
| Path: TK2MSFTNGXA02.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.webservices:30835
| NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
|
[quoted text clipped - 80 lines]
| | >
| | > #Standard DateTime Format Strings Output Examples

http://msdn.microsoft.com/library/en-us/cpguide/html/cpconstandarddatetimefo
| | > rmatstringsoutputexample.asp?frame=true
| | >
[quoted text clipped - 3 lines]
| | >
| | > #Coding Best Practices Using DateTime in the .NET Framework

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
| | > ml/datetimecode.asp
| | >
[quoted text clipped - 42 lines]
| | > |
| | > | TIA!
param@community.nospam - 15 Nov 2005 04:20 GMT
It worked. Thanks!

> Hi Param,
>
[quoted text clipped - 186 lines]
> | | > |
> | | > | TIA!
Steven Cheng[MSFT] - 15 Nov 2005 06:30 GMT
You're welcome Param,

Regards,

Steven Cheng
Microsoft Online Support

Signature

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: <param@community.nospam>
| References: <umrT5mH5FHA.3980@TK2MSFTNGP10.phx.gbl>
<aLYkSZP5FHA.832@TK2MSFTNGXA02.phx.gbl>
<#nDaf0T5FHA.2040@TK2MSFTNGP14.phx.gbl>
<OljTHub5FHA.1236@TK2MSFTNGXA02.phx.gbl>
<jiPrSeS6FHA.832@TK2MSFTNGXA02.phx.gbl>
| Subject: Re: datetime format in xml
| Date: Mon, 14 Nov 2005 22:20:35 -0600
[quoted text clipped - 9 lines]
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.webservices:30884
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
|
[quoted text clipped - 128 lines]
| > | | >
| > | | > #Standard DateTime Format Strings Output Examples

http://msdn.microsoft.com/library/en-us/cpguide/html/cpconstandarddatetimefo
| > | | > rmatstringsoutputexample.asp?frame=true
| > | | >
[quoted text clipped - 3 lines]
| > | | >
| > | | > #Coding Best Practices Using DateTime in the .NET Framework

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
| > | | > ml/datetimecode.asp
| > | | >
[quoted text clipped - 47 lines]
| > | | > |
| > | | > | TIA!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.