C#DateTime ToString [英] C# DateTime ToString

查看:65
本文介绍了C#DateTime ToString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#的新手,我写了一个简单的控制台应用程序来显示当前时间.

 System.Console.WriteLine(DateTime.Now.ToString(" ))



为什么特定格式"zzz"总是返回-07:00(我的预期结果是-08)

我的计算机(窗口服务器2008)的时区为:UTC-08:00太平洋时间(美国和加拿大)

请帮助我:(

解决方案

有关当前UTC时间,请参见以下链接:
http://www.worldtimeserver.com/current_time_in_UTC.aspx [ http://www.timeanddate.com/library/abbreviations/timezones/na/pdt.html [ ^ ]
因此,ToString方法的输出是正确的.效果.


I am newbie in c#, I write a simple console app to show current time.

System.Console.WriteLine(DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss zzz"))



Why the specific format "zzz" always return -07:00 (my expected result is -08)

My computer (window server 2008) timezone is : UTC-08:00 Pacific Time (US & Canada)

Please help me :(

解决方案

See this link for the current UTC time:
http://www.worldtimeserver.com/current_time_in_UTC.aspx[^]
Your current timezone is PDT time as explained below:
http://www.timeanddate.com/library/abbreviations/timezones/na/pdt.html[^]
So, the output of the ToString method is correct.


Console.WriteLine(DateTime.Now.ToShortDateString());


If you change the time zone, you must restart your computer to take effect.


这篇关于C#DateTime ToString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆