Functions for Date & Time

Get date

function GetDate() {
	var date = new Date();
	if ((date.getYear() - 100) < 10) {
		var year = "0" + new String((date.getYear() - 100));
	}
	else {
		var year = new String((date.getYear() - 100));
	}
	var dateString = (date.getMonth() + 1) + "/" + date.getDate() + "/" + year + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
	return dateString;
}

Change time by Peter Kahrel

The function's first parameter is a string specifying the number of hours to add or subtract, the second parameter indicates the clock type, 12 or 24 hrs. Sample calls:
change_time ("-1", 24); // subtract 1 hour, using a 24-hr clock
change_time ("+3", 12); // add 3 hours using a 12-hr clock

function change_time (n, clocktype)
    {
    app.findGrepPreferences = null;
    app.findGrepPreferences.findWhat = '\\d\\d?(?=:\\d\\d)';
    var hr, hours = app.documents[0].findGrep();
    for (var i = hours.length-1; i > -1; i--)
        {
        hr = eval ("Number(hours[i].contents)" + n);
        if (hr >= clocktype)
            hr = hr - clocktype;
        else
            if (hr < 0)
                hr = clocktype-Math.abs(hr);
        hours[i].contents = String (hr);
        }
    }

change_time ("-1", 24);

Current time

alert(currentTime());

function currentTime() {
var date = new Date();
var str = '';
var timeDesignator = ' T';
function _zeroPad(val) { return (val < 10) ? '0' + val : val; }
str = (date.getFullYear() + '-' +
	   _zeroPad(date.getMonth()+1,2) + '-' +
	   _zeroPad(date.getDate(),2));
str += (timeDesignator +
		_zeroPad(date.getHours(),2) + ':' +
		_zeroPad(date.getMinutes(),2) + ':' +
		_zeroPad(date.getSeconds(),2));
return str;
};