Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would you format DateTime in international format?

Tags:

c#

datetime

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);
like image 385
Aaron Avatar asked Jun 29 '10 15:06

Aaron


3 Answers

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

will output:

2010-06-29 08:25:16 -07:00
like image 200
Phil Lamb Avatar answered Oct 18 '22 19:10

Phil Lamb


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

like image 45
Mark Dykun Avatar answered Oct 18 '22 17:10

Mark Dykun


I would go with ISO format.

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

These are international standards.

like image 24
Will Marcouiller Avatar answered Oct 18 '22 19:10

Will Marcouiller