Create Valid Time Stamps For RSS 2.0 And Atom 1.0 Feeds.
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:
CreateRSSTime = Replace(Session("ServerGMT"), "UTC", "GMT")
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:
Dim sYear, sMonth, sDay, sHour, sMinute, sSecond
Dim arrUTC, arrUTCTime
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"
CreateAtomTime should return 2006-04-12T23:20:50Z, a valid timestamp as defined in RFC3339.
Your web server must be set up with correct time zone and daylight savings time (if required).