Created
December 10, 2012 12:58
-
-
Save radleta/4250401 to your computer and use it in GitHub Desktop.
Date and Time conversion local to and from UTC for ASP.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
' **************************************************************************** | |
' Sub: GetUtcOffsetMinutes | |
' Description: Gets the number of minutes between local time and UTC. | |
' | |
' Params: None | |
' **************************************************************************** | |
Function GetUtcOffsetMinutes() | |
Dim key | |
key = "UtcOffsetMinutes" | |
GetUtcOffsetMinutes = Application(key) | |
If IsEmpty(GetUtcOffsetMinutes) Then | |
'Create Shell object to read registry | |
Dim oShell, atb, offsetMinutes | |
Set oShell = CreateObject("WScript.Shell") | |
'Reading the registry | |
GetUtcOffsetMinutes = oShell.RegRead("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias") | |
Application(key) = GetUtcOffsetMinutes | |
Set oShell = Nothing | |
End If | |
End Function | |
' **************************************************************************** | |
' Sub: ConvertToUtcTime | |
' Description: Converts the local time to UTC time. | |
' | |
' Params: localDateTime: The local time to convert to UTC time. | |
' **************************************************************************** | |
Function ConvertToUtcTime(localDateTime) | |
ConvertToUtcTime = DATEADD("n", GetUtcOffsetMinutes(), localDateTime) | |
End Function | |
' **************************************************************************** | |
' Sub: ConvertToLocalTime | |
' Description: Converts the UTC time to local time. | |
' | |
' Params: utcDateTime: The UTC time to convert to local time. | |
' **************************************************************************** | |
Function ConvertToLocalTime(utcDateTime) | |
ConvertToLocalTime = DATEADD("n", -(GetUtcOffsetMinutes()), utcDateTime) | |
End Function | |
%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment