8

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);
Aaron
  • 95
  • 2
  • 6

6 Answers6

15
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss zzz");

will output:

2010-06-29 08:25:16 -07:00
Phil Lamb
  • 1,407
  • 10
  • 15
2

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

Mark Dykun
  • 79
  • 1
1

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
  • 23,773
  • 22
  • 96
  • 162
  • that would probably be better but I'm trying to pass the date back and forth from objective-c. – Aaron Jun 29 '10 at 15:31
0

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

Oh I see, sorry misunderstood the question.

Adam Houldsworth
  • 63,413
  • 11
  • 150
  • 187
0

You want to use DateTimeOffset.

DarthVader
  • 52,984
  • 76
  • 209
  • 300
0

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
  • 106,783
  • 21
  • 203
  • 265
  • https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings#the-sortable-s-format-specifier as per Mark Dykun's answer below this works – AussieALF Jul 12 '18 at 04:54