Get current date in international format (ISO 8601)

Get current date in international format (ISO 8601)

Sometimes it’s useful to avoid having potential problems with date formats.. so i often use the international format to work with dates..
The following java function (Client- or Server side) returns the current date in the format
yyyy-mm-ttThh:mm:ss

 

function getIsoDateTime() {
	var today = new Date();
	var year = today.getYear();
	if (year < 2000) // Y2K Fix, Isaac Powell
		year = year + 1900; // http://onyx.idbsu.edu/~ipowell
	var month = today.getMonth() + 1;
	var day = today.getDate();
	var hour = today.getHours();
	var minute = today.getMinutes();
	var second = today.getSeconds();
	if (month <= 9) month = "0" + month;
	if (day <= 9) day = "0" + day;
	if (hour <= 9) hour = "0" + hour;
	if (minute <= 9) minute = "0" + minute;
	if (second <= 9) second = "0" + second;
	time = year + "-" + month + "-" + day + "T"
	+ hour + ":" + minute + ":" + second;
	return time;
}

Leave a Reply

comment-avatar

*