如何从mvc 4中的其他位置获得时间 [英] how to get uk time from other location in mvc 4

查看:78
本文介绍了如何从mvc 4中的其他位置获得时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站现在在我们的服务器上我的问题是如何获得当前时间。

解决方案

您需要获取UTC时间然后将其转换为期望的时区。看看.NET全球化功能。这个链接可以帮助你入门:

MSDN :转换时区之间的时间 [ ^ ]


您可以使用 TimeZoneInfo.ConvertTimeBySystemTimeZoneId

 DateTime ukTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.Now,  GMT标准时间< /跨度>); 


my website is in us server now my problem is how to get uk current time .

解决方案

You need to get the UTC time and then convert it to the desired time zone. Take a look at the .NET globalization features. This link should get you started:
MSDN: Converting Times Between Time Zones[^]


You can use TimeZoneInfo.ConvertTimeBySystemTimeZoneId:

DateTime ukTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.Now, "GMT Standard Time");


这篇关于如何从mvc 4中的其他位置获得时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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