开发者

How would you format DateTime in international format?

The internat开发者_如何学Pythonional 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);


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

will output:

2010-06-29 08:25:16 -07:00


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


I would go with ISO format.

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

These are international standards.


You want to use DateTimeOffset.


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

Oh I see, sorry misunderstood the question.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜