i know there is not any way to change timezone of an application globaly, but is there any way to store datetimes in utc on sqlserver. right now any time i submit to server considerd as local. i can change that by ConvertToUTC() method in .net.

有帮助吗?

解决方案 2

I Think easiest way is to use a function inside my application to fix time zone for me then send data to/From Server. I used 2 different functions :

 Friend tZone As TimeZoneInfo

 Public Function TimeZone_Get(ByVal time As DateTime, ByVal Tolocal As Boolean) As DateTime
    Dim t As DateTime = time

    If Tolocal = True Then
        t = TimeZoneInfo.ConvertTimeFromUtc(time, tZone)
    End If
    Return t
End Function

Public Function TimeZone_Set(ByVal time As DateTime, ByVal Islocal As Boolean) As DateTime
    Dim t As DateTime = time
    If Islocal = True Then
        t = TimeZoneInfo.ConvertTimeToUtc(time, tZone)
    End If
    Return t
End Function

其他提示

You could consider using the SQL function:

getUTCdate();

See here for more info: http://technet.microsoft.com/en-us/library/ms178635.aspx

Note the UTC datetime is derived from the Operating System of which the SQL Server is running.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top