'============================================================ ' AUTHOR: Terje Hauger ' CREATED: Mars 2006 ' HOME: http://www.u229.no/stuff/snippets/RFC822ToLocalTime.asp '============================================================ '// This example will be converted to 27.02.06 03:02:04 on my web server. Response.Write RFC822ToLocalTime("Mon, 27 Feb 2006 04:02:04 +0200", "+0100") '------------------------------------------------------------------------------------------------------------ ' Comment: Convert a RFC822 timestamp into your web servers local time zone. '------------------------------------------------------------------------------------------------------------ Function RFC822ToLocalTime(sRFC822, sServerOffset) Dim arrTmp, arrTime, tmpDate Dim yyyy, mm, dd, h, m, s Dim iLocalHours, iLocalMinutes, iServerHours, iServerMinutes, iLocalOffset '// Read the date values arrTmp = Split(sRFC822, Chr(32)) yyyy = arrTmp(3) mm = Right("0" & CStr(ConvertMonthName(arrTmp(2))), 2) dd = Right("0" & arrTmp(1), 2) '// Read the time values arrTime = Split(arrTmp(4), ":") h = Right("0" & arrTime(0), 2) m = Right("0" & arrTime(1), 2) s = Right("0" & arrTime(2), 2) '// We need this for vbscript's DateAdd function. tmpDate = dd & "-" & arrTmp(2) & "-" & yyyy & Chr(32) & h & ":" & m & ":" & s '// Read the timezone information On Error Resume Next iLocalOffset = CInt(arrTmp(5)) iLocalHours = CInt(Mid(arrTmp(5), 1, 3)) iLocalMinutes = CInt(Mid(arrTmp(5), 4, 2)) If Err Then iLocalOffset = 0: iLocalHours = 0: iLocalMinutes = 0 iServerHours = CInt(Mid(sServerOffset, 1, 3)) iServerMinutes = CInt(Mid(sServerOffset, 4, 2)) '// Local time zone is ahead of web server If iLocalOffset > CInt(sServerOffset) Then tmpDate = DateAdd("h", - (iLocalHours - iServerHours), tmpDate) If iLocalMinutes > iServerMinutes Then tmpDate = DateAdd("n", - (iLocalMinutes - iServerMinutes), tmpDate) '// Web servers time zone is ahead of local time If iLocalOffset < CInt(sServerOffset) Then tmpDate = DateAdd("h", iServerHours - iLocalHours, tmpDate) If iLocalMinutes < iServerMinutes Then tmpDate = DateAdd("n", iServerMinutes - iLocalMinutes, tmpDate) RFC822ToLocalTime = tmpDate End Function Function ConvertMonthName(sMonth) Select Case UCase(Mid(sMonth, 1, 3)) Case "JAN": ConvertMonthName = 1 Case "FEB": ConvertMonthName = 2 Case "MAR": ConvertMonthName = 3 Case "APR": ConvertMonthName = 4 Case "MAY": ConvertMonthName = 5 Case "JUN": ConvertMonthName = 6 Case "JUL": ConvertMonthName = 7 Case "AUG": ConvertMonthName = 8 Case "SEP": ConvertMonthName = 9 Case "OCT": ConvertMonthName = 10 Case "NOV": ConvertMonthName = 11 Case "DEC": ConvertMonthName = 12 Case Else: ConvertMonthName = 0 End Select End Function