日期格式YYYY-MM-DDTHH:MM:SSZ [英] date format yyyy-MM-ddTHH:mm:ssZ
问题描述
我想这应该是pretty简单,但无法得到它:(。
在此格式中,Z是时区。
T是很长一段时间模式
我怎么能拿这种格式的日期,除非使用
DateTime的DT = DateTime.Now;
Console.WriteLine(dt.ToString(YYYY-MM-DDTHH:MM:SSZ));
在C#
使用UTC
Console.WriteLine(DateTime.UtcNow.ToString(S)+Z);
2009-11-13T10:39:35Z
块引用>在以Z 是那里,因为
如果时间是UTC,添加一个'Z'
的情况下直接涉及的时间之后
空间。 Z是用于区指示符
零UTC时差。 UTC 09:30是
因此,重新psented为$ P $09:30Z或
0930Z。 14点45分15秒UTC将是
14:45:15Z或144515Z
块引用>如果你想包括偏置
INT小时= TimeZoneInfo.Local.BaseUtcOffset.Hours;
字符串偏移=的String.Format({0} {1},((小时大于0)+:),hours.ToString(00));
串isoformat = DateTime.Now.ToString(S)+偏移量;
Console.WriteLine(isoformat);有两点需要注意:+或 - 时间之后需要,但显然+不上正数显示。根据维基百科的偏移量可在+ HH格式或+ HH:MM。我不停地几个小时。
据我所知, RFC1123 的(HTTP日期,U格式)并不意味着放弃时区偏移。所有时间都意在GMT / UTC。
I assume this should be pretty simple, but could not get it :(. In this format Z is time zone.
T is long time pattern
How could I get a date in this format except by usingDateTime dt = DateTime.Now; Console.WriteLine(dt.ToString("yyyy-MM-ddTHH:mm:ssZ"));
in C#
解决方案Using UTC
ISO 8601 (MSDN datetime formats)
Console.WriteLine(DateTime.UtcNow.ToString("s") + "Z");
2009-11-13T10:39:35Z
The Z is there because
If the time is in UTC, add a 'Z' directly after the time without a space. 'Z' is the zone designator for the zero UTC offset. "09:30 UTC" is therefore represented as "09:30Z" or "0930Z". "14:45:15 UTC" would be "14:45:15Z" or "144515Z".
If you want to include an offset
int hours = TimeZoneInfo.Local.BaseUtcOffset.Hours; string offset = string.Format("{0}{1}",((hours >0)? "+" :""),hours.ToString("00")); string isoformat = DateTime.Now.ToString("s") + offset; Console.WriteLine(isoformat);
Two things to note: + or - is needed after the time but obviously + doesn't show on positive numbers. According to wikipedia the offset can be in +hh format or +hh:mm. I've kept to just hours.
As far as I know, RFC1123 (HTTP date, the "u" formatter) isn't meant to give time zone offsets. All times are intended to be GMT/UTC.
这篇关于日期格式YYYY-MM-DDTHH:MM:SSZ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!