0

Possible Duplicate:
In C#, given a DateTime object, how do I get a ISO 8601 date in string format?

In my .NET C# program I'm using CookComputing.XmlRpcV2.dll

I have an XMLRPC client that needs to connect to a xmlrpc server. I need to send an iso8601 datetime format with time zone (20121018T00:00:12+0200). So far I have tried Convert.ToDateTime(DateTime.UtcNow.ToString("o")), but this returns <dateTime.iso8601>20121009T16:06:47</dateTime.iso8601>, which is not the desire result I'm looking for.

Community
  • 1
  • 1
  • Have a look at: [http://stackoverflow.com/questions/114983/in-c-given-a-datetime-object-how-do-i-get-a-iso-8601-date-in-string-format][1] [1]: http://stackoverflow.com/questions/114983/in-c-given-a-datetime-object-how-do-i-get-a-iso-8601-date-in-string-format – lboshuizen Oct 18 '12 at 13:27

1 Answers1

0
DateTime.UtcNow.ToString("yyyy-MM-ddTHH\:mm\:ss.fffffffzzz");

This gives you a date similar to 2012-10-18T13:57:31.2311892-04:00

Another way is:

DateTime.UtcNow.ToString("o");

which gives you 2012-10-18T14:01:54.9571247Z

To get the format you want, you can use:

 DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ")
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
  • the result still the same as 20121018T13:49:20. I dont know may be CookComputing.XmlRpcV2.dll contraining the value. – user1756284 Oct 18 '12 at 14:01
  • can u share d exact DateTime.UtcNow.ToString(args) u hv used? – Milind Anantwar Oct 18 '12 at 14:23
  • BalanceStructRequest ssr = new BalanceStructRequest("EXT", "76639511", "1", Convert.ToDateTime(DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ")), "slapps01"); proxy.GetBalance(ssr); – user1756284 Oct 18 '12 at 15:19