Converting a JavaScript Date object into the proper XML string


function SwConvertDateTimeToXml(dateTime) {

var offset = (ORG_TIMEZONE_OFFSET < 0) ? -ORG_TIMEZONE_OFFSET : ORG_TIMEZONE_OFFSET;
var timezoneOffsetHours = Math.floor(offset / 60);
var timezoneOffsetMinutes = offset - timezoneOffsetHours * 60;

var s =
dateTime.getYear().toString() + "-" +
SwGetFormattedDatePart(dateTime.getMonth() + 1) + "-" +
SwGetFormattedDatePart(dateTime.getDate()) + "T" +
SwGetFormattedDatePart(dateTime.getHours()) + ":" +
SwGetFormattedDatePart(dateTime.getMinutes()) + ":" +
SwGetFormattedDatePart(dateTime.getSeconds()) +
((ORG_TIMEZONE_OFFSET < 0) ? "-" : "+") +
SwGetFormattedDatePart(timezoneOffsetHours) + ":" +
SwGetFormattedDatePart(timezoneOffsetMinutes);

return s;
}

function SwGetFormattedDatePart(value) {
return (value < 10) ? ("0" + value.toString()) : value.toString();
}