How to change the formatting of System.DateTime.Now without convert to string type  
Author Message
traderhen





PostPosted: Visual C# General, How to change the formatting of System.DateTime.Now without convert to string type Top

Does anyone know how to change the formatting of System.DateTime.Now, but not have it outputted to a String type.

I have a SOAP webservice element that only accepts a dateTime type and format similar to this:
2006-12-04T17:21:42.788Z

I'm using the following code below, but need to change its formatting to conform to the sample above:
meterRequest.serviceRequestTimeStamp = System.DateTime.Now;

Thanks,
Henry



Visual C#3  
 
 
OmegaMan





PostPosted: Visual C# General, How to change the formatting of System.DateTime.Now without convert to string type Top

If the function requires a DateTime object, where does the ToString come into play

Data access functionality internally is not done by ToString() but by specific properties which return integers. If you need to format a string to a specific output, then you will need to use ToString with format specifiers such as ToString("MMddyyyy tt") depending on what is required.

 
 
Markku Behm





PostPosted: Visual C# General, How to change the formatting of System.DateTime.Now without convert to string type Top

Hi

You can try this:

DateTime.Now.ToString("yyyy-MM-ddThh:mm:ss.ffffZ");

Yours
Markku


 
 
Peter Ritchie





PostPosted: Visual C# General, How to change the formatting of System.DateTime.Now without convert to string type Top

You can use the XmlSerializer class to output DateTime objects as xml date time types.