convert datetime to sortable format

P

pranesh.nayak

Hello again,

I need to convert date to "yyyy-MM-ddTHH:mm:ss" format.

Below code does this, but it appends time twice in date variable.

DateTimeFormatInfo dy = new DateTimeFormatInfo();
dy.ShortDatePattern = "yyyy-MM-ddTHH:mm:ss";
dy.ShortTimePattern = "";
// next set dy to current culture
System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat =
dy;
// now parse the date
DateTime date = DateTime.Parse("2006/12/12", new CultureInfo("en-US"),
DateTimeStyles.None);

This is appending time twice in date variable, (eg:
"2006/12/12T01:00:00 01:00:00")

I need to pass this variable (as DateTime type) to Java webservice.

any suggestions on how to get the date in reqd format?

Thanks
 
K

Kevin Spencer

Does the web service take a DateTime data type or a string?

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Big thicks are made up of lots of little thins.
 
S

Sanjib Biswas

Have you tried the following code?

dy.ShortDatePattern = "yyyy-MM-ddT";
dy.ShortTimePattern = "HH:mm:ss";
 
P

pranesh.nayak

Webservice takes DateTime data type as parameter..

after debugging more I found that .Net runtime is not recognising
xs:DateTime format.

When I try to read data from that webservice got an error sayign:
"String was not recognized as a valid DateTime".

So we can conclude that xs:DateTime format is incompatible with .Net.
Please refer this article :
http://www.mcse.ms/archive105-2004-7-899102.html
about similar problem.

since its a 3rd party webservice i can't touch it. The other solution
given in this article (using [XMLIgnore]) did not work for me.

Please advise if you have any idea abt this.

Thanks..
Raghu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top