tags:

views:

81

answers:

6

The international string representation format is (YYYY-MM-DD HH:MM:SS ±HHMM).

e.g. 2010-06-10 21:21:10 -0400

basically the problem I am having is figuring out how to get the difference from GMT.

DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123);
String.Format("{0:yyyy-MM-dd HH:mm:ss ????}", dt);
A: 

I think that is shown in the hours. That -4 is the difference from GMT.

Oh I see, sorry misunderstood the question.

Adam
+8  A: 
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss zzz");

will output:

2010-06-29 08:25:16 -07:00
Phil Lamb
perfect. thanks. I can strip out the : pretty easy.
Aaron
@Aaron: The `±HH:mm` format, including a `:`, is legal in ISO8601.
LukeH
it is legal but its not the format objective-c uses.
Aaron
A: 

You want to use DateTimeOffset.

+1  A: 

I would go with ISO format.

And the W3C has also a note on the topic: Date and Time Formats.

These are international standards.

Will Marcouiller
that would probably be better but I'm trying to pass the date back and forth from objective-c.
Aaron
A: 

How would you format DateTime in international format?

You can use a custom format specifier (there is no standard formats for ISO standard date/time formats).

the problem I am having is figuring out how to get the difference from GMT.

Parse using one of DateTimeOffset's static methods, and then check the Offset property.

Or if you mean, how to include the offset in the string: use DateTimeOffset with the correct timezone and a custom format specifier.

Richard
A: 

string isoFormat = inputDateTime.Format("s");

Mark Dykun