以这种格式显示当前时间:HH:mm:ss

发布于 2024-09-12 12:00:54 字数 270 浏览 4 评论 0原文

我在以这种格式显示时间时遇到一些问题:HH:mm:ss。 无论我尝试什么,我都不会以这种格式得到它。

我想要在荷兰文化中度过一段时间,即“nl-NL”。

这是我(虽然我忘了数)第 1000 次尝试之一:

CultureInfo ci = new CultureInfo("nl-NL");

string s = DateTime.Now.TimeOfDay.ToString("HH:mm:ss", ci);

我做错了什么?

I'm having some trouble displaying the time in this format: HH:mm:ss.
No matter what i try, i never get it in that format.

I want the time in the culture of the Netherlands which is "nl-NL".

This was one of my (although i forgot to keep the count) 1000th try:

CultureInfo ci = new CultureInfo("nl-NL");

string s = DateTime.Now.TimeOfDay.ToString("HH:mm:ss", ci);

What am i doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

潜移默化 2024-09-19 12:00:54
string s = DateTime.Now.ToString("HH:mm:ss");
string s = DateTime.Now.ToString("HH:mm:ss");
尐偏执 2024-09-19 12:00:54

您需要使用 TimeZoneInfo 类,以下是显示当前时间的方法东部标准时间时区,格式为HH:mm:ss:

var timeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
string s = TimeZoneInfo.ConvertTime(DateTime.Now, timeZone).ToString("HH:mm:ss");

要查找所有可用的时区,您可以使用

TimeZoneInfo.GetSystemTimeZones();

从上面的返回值中查看,您需要的时区的Id(我假设是阿姆斯特丹)称为W欧洲标准时间:

var timeZone = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");
string s = TimeZoneInfo.ConvertTime(DateTime.Now, timeZone).ToString("HH:mm:ss");

You need to use the TimeZoneInfo class, here's how to show the current time in the Eastern Standard Time time zone in HH:mm:ss format:

var timeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
string s = TimeZoneInfo.ConvertTime(DateTime.Now, timeZone).ToString("HH:mm:ss");

To find all the timezones available, you can use

TimeZoneInfo.GetSystemTimeZones();

Looking through the returned value from the above, the Id for the time zone you need (Amsterdam I assume) is called W. Europe Standard Time:

var timeZone = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");
string s = TimeZoneInfo.ConvertTime(DateTime.Now, timeZone).ToString("HH:mm:ss");
你没皮卡萌 2024-09-19 12:00:54

TimeOfDay是一个TimeSpan,它只有一个不带参数的ToString()。
使用 Darin 的解决方案 或来自 TimeSpan.ToString() 的 MSDN 文档

TimeOfDay is a TimeSpan, which has only one ToString() without parameters.
Use Darin's solution or a sample from MSDN documentation for TimeSpan.ToString()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文