如何从特定的TimeZone获取日期和时间? [英] How to get Date and Time from specific TimeZone ?

查看:427
本文介绍了如何从特定的TimeZone获取日期和时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能帮助我吗,我作为DispalyName输入了输入(例如:(GMT-06:00)中美洲

)然后我想得到当前的日期和时间。

Could you please help me, I gave input as DispalyName (eg:(GMT-06:00) Central America
) then i want to get current date and time .

推荐答案

这适用于.net 4.0,在TimeZoneInfo类中没有Metro风格应用中的FindSytemTimeZone方法。那么如何在地铁风格的应用中做到这一点...



string ZoneId =Central America;

DateTime localtime = DateTime.Now ;

TimeZoneInfo timeZoneInfo = System.TimeZoneInfo.FindSystemTimeZoneById(ZoneId);

DateTime dataTimeByZoneId = System.TimeZoneInfo.ConvertTime(localtime,System.TimeZoneInfo.Local,timeZoneInfo);

返回dataTimeByZoneId;
This is works on .net 4.0, In TimeZoneInfo class doesn't have a FindSytemTimeZone method in metro style apps. So how to do this in metro style apps...

string ZoneId = "Central America";
DateTime localtime = DateTime.Now;
TimeZoneInfo timeZoneInfo = System.TimeZoneInfo.FindSystemTimeZoneById(ZoneId);
DateTime dataTimeByZoneId = System.TimeZoneInfo.ConvertTime(localtime, System.TimeZoneInfo.Local, timeZoneInfo);
return dataTimeByZoneId;


使用 callisto [ ^ ]控件


你必须看到这篇文章如何按时区查找日期和时间使用c#



这是一个非常好的实现!适用于所有类型的.NET项目。



希望它有所帮助。
You must see this post How to Find Date and Time by Time Zone using c#

It's a very nice implementation! Works in all type of .NET projects.

Hope it helps.


这篇关于如何从特定的TimeZone获取日期和时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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