u229
Applications Home|Email

 Convert RFC822 date stamps to local web server time.

This routine converts time stamps like Mon, 27 Feb 2006 04:02:04 +0100, used with RSS 2.0 feeds, into your local time (your web servers local time). The routine takes two parameters: a RFC822 formatted time stamp and your web servers time zone.

'// 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")
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

- Documentation for RFC822

- View RFC822ToLocaltime.txt.

Therefore: For that or this for it.
© www.u229.no