in Web Development

Time String in RFC733 Format

A function to format a time string according to the frankly obsolete RFC733 standard published 1977-11-21. This was necessary as I was generating some OPML which for whatever reason uses this format.

function rfc733String( i )
{ // IN: formatted time string OUT: RFC733 UTC time string
	if ( i == undefined ) {
		var d = new Date();
	}
	else {
		var d = new Date( i );
	}
	function padnmbr(n) // IN: 0-99 OUT: 00 - 99 formatted thus
	{
		if ( n < 10 ) {
			return '0' + n;
		}
		else {
			return n;
		}
	}
	var days = [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'  ];
	var mths = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
	             'Sep', 'Oct', 'Nov', 'Dec' ];
	var s = days[ d.getUTCDay() ] + ', ' + padnmbr( d.getUTCDate() ) + ' ' +
	mths[ d.getUTCMonth() ] + ' ' + padnmbr( d.getUTCHours() ) + ':' +
	padnmbr( d.getUTCMinutes() ) + ':' + padnmbr( d.getUTCSeconds() ) +
	' ' + d.getUTCFullYear() + ' Z';
	return s;
} // -- rfc733String

Your thoughts? Click here to comment.

Comment

All fields voluntary.
Comment submission rules apply.