开发者

How to determine local representation of a specific GMT datetime

I want to get the date value for

Nov 1, 2010 00:00:00 GMT

express开发者_JAVA技巧ed in my local time.

What is the best way? Currently, I am doing this:

    Dim NovGmt As Date = New Date(2010, 11, 1, 0, 0, 0)
    Dim Nov1AsLocal As Date = GetGmtExpressedAsLocal(NovGmt)



   Private Function GetGmtExpressedAsLocal(ByVal gmtDate As Date) As Date
        Return gmtDate.AddMinutes(GetMinuteOffsetFromGmt)
    End Function

   Private Function GetMinuteOffsetFromGmt() As Double

       Dim NowTime As Date = Now
       Dim NowAsGmt As Date = NowTime.ToUniversalTime

       Return CType(DateDiff(DateInterval.Minute, NowAsGmt, NowTime), Double)

   End Function

Also, can somebody tell me difference between the Date and DateTime datatypes? Is DateTime newer than Date or is it just a synonym for Date? If the latter, why have both?


You can use the ToLocalTime to convert a DateTime from UTC to the local timezone.

Date is an alias for DateTime. I presume this was done for backward compatibility reasons.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜