如何获取不同国家的当前时间在C# [英] How to get current time of different countries in C#

查看:191
本文介绍了如何获取不同国家的当前时间在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用C#获取不同国家的当前时间,使用以下任意参数:
1.country name
2.国家/地区的时区

How to get current time of different countries in C# by using following any parameters, 1.country name 2.Timezone of country

这是用于 Windows / WPF应用程序,不像Web
任何人都可以回答这个问题吗?
提前感谢。

This is for Windows / WPF Applications, not like Web Could anyone please answer this? Thanks in advance.

推荐答案

您应该看看 TimeZoneInfo 课程,特别是 TimeZoneInfo.ConvertTime方法

You should look at TimeZoneInfo class, specifically at TimeZoneInfo.ConvertTime method.

例如,要获取中欧的当前时间:

For example, to get current time in Central Europe:

var remoteTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time");
var remoteTime = TimeZoneInfo.ConvertTime(DateTime.Now, remoteTimeZone);
Console.WriteLine("Time in {0} is {1}", remoteTimeZone.Id, remoteTime.TimeOfDay.ToString());

这篇关于如何获取不同国家的当前时间在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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