Applications Home|Email

 Create Valid Time Stamps For RSS 2.0 And Atom 1.0 Feeds.

A typical RSS 2.0 time reads Wed, 01 Feb 2006 15:00:00 GMT, and a typical Atom 1.0 time 2006-04-12T23:20:50Z. They conform to two different specifications, namely RFC822 and RFC3339.

Many news feeds use the offset between local time and UTC with syntax like +01:00 or -00:20, which means 1 hour ahead of UTC and 20 minutes after UTC. My approach is to use UTC time only. Then it will be up to the feed reader software to convert these timestamps to a local format, if that is required. It just seems to be the best way to deal with different time zones in terms of xml feeds.

Vbscript has no in built UTC functionality, so we have to use a workaround. My approach is to use JScript, because JScript has access to the web servers time zone offset and can also convert a local time to UTC time. But how do you transfer a jscript variable to vbscript? Luckily, they both share the Session and Application objects provided by ASP, so we simply tell JScript to store the UTC value in a session variable which we can access using vbscript.

This jscript code should create something like Wed, 01 Feb 2006 15:00:00 UTC:

    var od = new Date();
    var nd = od.toGMTString();
    Session("ServerGMT") = nd;

Now we have the current UTC time held in a session variable, and we can use this value in creating timestamps for both RSS and Atom feeds. First the RSS 2.0 timestamp:

Function CreateRSSTime()

    Server.Execute "GetServerGMT.asp"

    CreateRSSTime = Replace(Session("ServerGMT"), "UTC", "GMT")

End Function

This should return something like Wed, 01 Feb 2006 15:00:00 GMT, which is valid according to RFC822. Creating a valid timestamp for a Atom 1.0 feed is a little more complicated:

Function CreateAtomTime()

    Dim sYear, sMonth, sDay, sHour, sMinute, sSecond
    Dim arrUTC, arrUTCTime

    Server.Execute "GetServerGMT.asp"

    arrUTC = Split(Session("ServerGMT"), Chr(32))
    arrUTCTime = Split(arrUTC(4), ":")

    sYear = arrUTC(3)
    sMonth = Right("0" & ConvertUTCMonth(arrUTC(2)), 2)
    sDay = Right("0" & arrUTC(1), 2)
    sHour = arrUTCTime(0)
    sMinute = arrUTCTime(1)
    sSecond = arrUTCTime(2)

    CreateAtomTime = sYear & "-" & sMonth & "-" & sDay & "T" & sHour & ":" & sMinute & ":" & sSecond & "Z"

End Function

CreateAtomTime should return 2006-04-12T23:20:50Z, a valid timestamp as defined in RFC3339.

View TimeStamps.txt.

Your web server must be set up with correct time zone and daylight savings time (if required).

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