Jump to content

User:Dragon695/datetime.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
<!--
 // -->[[User:Dragon695/datetime.js]] - Defines ISO timestamp functions.

<!--
 // -->Taken from [[User:Quarl/datetime.js]].

<!--
 // --><table class="wikitable">
<!--
 // --><caption><b><u>Version History</u></b></caption>
<!--
 // --><tr><th>Rev.</th><th>Editor</th><th>Date</th><th>Comments</th></tr>
<!--
 // --><tr><td>1.1</td><td>[[User:Quarl|quarl]]</td><td>2005-12-30</td><td>Initial version</td></tr>
<!--
 // --><tr><td>1.2</td><td>[[User:Quarl|quarl]]</td><td>2005-12-30</td><td>None</td></tr>
<!--
 // --><tr><td>1.3</td><td>[[User:Quarl|quarl]]</td><td>2006-01-10</td><td>datestampYYYYMonthD, datestampMonthYYYY</td></tr>
<!--
 // --><tr><td>1.4</td><td>[[User:Quarl|quarl]]</td><td>2006-01-10</td><td>None</td></tr>
<!--
 // --><tr><td>1.5</td><td>[[User:Quarl|quarl]]</td><td>2006-01-24</td><td>e</td></tr>
<!--
 // --><tr><td>1.6</td><td>[[User:Quarl|quarl]]</td><td>2006-01-24</td><td>d</td></tr>
<!--
 // --><tr><td>1.7</td><td>[[User:Quarl|quarl]]</td><td>2006-01-24</td><td>previousDay</td></tr>
<!--
 // --><tr><td>1.8</td><td>[[User:Quarl|quarl]]</td><td>2006-02-01</td><td>array</td></tr>
<!--
 // --></table>

// <pre><nowiki>


monthnames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

//
// Return N days ago (default today).
//
function previousDay(days) {
	days = days || 0;
	var d = new Date();

	//
	// Automatically wraps as necessary.
	//
	d.setDate(d.getDate() - days);

	return (d);
}

function LZ(x) {
	return ((x >= 10 || x < 0 ? "" : "0") + x)
}

function datestampUTCISO(d) {
	d = d || new Date();

	return ("" + d.getUTCFullYear() + "-" + LZ(d.getUTCMonth() + 1) + "-" + LZ(d.getUTCDate()));
}

function timestampUTCISO(d) {
	d = d || new Date();

	return (LZ(d.getUTCHours()) + ":" + LZ(d.getUTCMinutes()));
}

function datestampYYYYMonthD(d) {
	d = d || new Date();

	return ("" + d.getUTCFullYear() + ' ' + monthnames[d.getUTCMonth()] + ' ' + d.getUTCDate());
}

function datestampMonthYYYY(d) {
	d = d || new Date();

	return ("" + monthnames[d.getUTCMonth()] + ' ' + d.getUTCFullYear());
}


// </nowiki></pre>