计算时区的简便方法? [英] Easy Method to Calcuate Time Zones?

查看:74
本文介绍了计算时区的简便方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我正在尝试创建一个非常简单的WPF应用程序,当按下按钮时会打印出位于的日期和时间那个按钮。例如,按获取英国时间将运行事件处理程序,并将该时间放在文本框中。



我查看了DateTime对象类,但是我没有看到任何其他时区的支持。



我是否需要在某个地方手动将小时数添加到某些代码中,或者有更简单的方法吗?

解决方案

听起来你需要这里的信息 http ://msdn.microsoft.com/en-us/library/system.timezoneinfo(v = vs.100).aspx [ ^ ] - 检查BaseUTCOffset,也许在这里http://msdn.microsoft.com/en-us/library/bb397781(v=vs.110).aspx [ ^ ]和 http://msdn.microsoft.com/en -us / library / bb546099(v = vs.110).aspx [ ^ ]


试试这个



  private   void  Form1_Load( object  sender,EventArgs e)
{
ReadOnlyCollection< timezoneinfo> tzCollection;
tzCollection = TimeZoneInfo.GetSystemTimeZones();
this .timeZoneList.DataSource = tzCollection;
}

private void OkButton_Click( object sender,EventArgs e)
{
TimeZoneInfo selectedTimeZone =(TimeZoneInfo) this .timeZoneList.SelectedItem;
MessageBox.Show( 您选择了 + selectedTimeZone.ToString()+ 时区。);
}
< / timezoneinfo >


Hi there,

I'm trying to create a very simple WPF Application that when a button is hit will print out the date and time that is located on that button. For instance pressing"Get UK Time" will run the event handler, and put that time in a text box.

I've looked at the DateTime object classes, but I don't see any support for other time zones.

Do I need to manually add the hours into some code somewhere, or is there an easier way to do this?

解决方案

sounds like you need the info from here http://msdn.microsoft.com/en-us/library/system.timezoneinfo(v=vs.100).aspx[^] -Check out BaseUTCOffset and maybe here http://msdn.microsoft.com/en-us/library/bb397781(v=vs.110).aspx[^] and http://msdn.microsoft.com/en-us/library/bb546099(v=vs.110).aspx[^]


try this

private void Form1_Load(object sender, EventArgs e)
{
   ReadOnlyCollection<timezoneinfo> tzCollection; 
   tzCollection = TimeZoneInfo.GetSystemTimeZones();
   this.timeZoneList.DataSource = tzCollection;
}

private void OkButton_Click(object sender, EventArgs e)
{
   TimeZoneInfo selectedTimeZone = (TimeZoneInfo) this.timeZoneList.SelectedItem;
   MessageBox.Show("You selected the " + selectedTimeZone.ToString() + " time zone.");
}
</timezoneinfo>


这篇关于计算时区的简便方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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