VB.NET-查找当前时区,然后转换为太平洋 [英] VB.NET - Find current timezone, then convert to Pacific

查看:97
本文介绍了VB.NET-查找当前时区,然后转换为太平洋的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试搜索代码,但是运气不太好。我发现了一些摘要,并且知道如何将当前时间转换为UTC,但是我只想知道如何获取当前时区,然后将时间转换为太平洋时间。

I tried searching around for the code, but I didn't have too much luck. I found little snippets and I know how to convert current time to UTC, but I just really want to know how to get the current time zone, then convert the time to pacific.

从加利福尼亚到缅因州,我有很多用户一直在使用我的软件。因此,我需要找出它们所在的时区,然后将其转换为太平洋时区,无论它们身在何处,这样我都可以准确地将本地时间与服务器时间进行比较。

I have many users that use my software all the way from california to maine. So I need to find out what timezone they are in, then convert it to pacific no matter where they are so I can accurately compare the local time to my servers time.

推荐答案

您可以使用TimeZoneInfo类为您转换时区:

You can use the TimeZoneInfo class to convert time zones for you:

    Dim now As DateTime = DateTime.Now
    MessageBox.Show(now.ToString())

    Dim pacificNow = System.TimeZoneInfo.ConvertTime(now, TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"))
    MessageBox.Show(pacificNow.ToString())

您可以阅读有关时区和MSDN。

You can read more about the TimeZones and the Ids on MSDN.

这篇关于VB.NET-查找当前时区,然后转换为太平洋的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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