Jump to content

User:Quarl/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.
// <pre><nowiki>

// return N days ago (default today)
function previousDay(days) {
    days = days || 0;
    var d = new Date();
    d.setDate(d.getDate() - days); // automatically wraps as necessary
    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());
}

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

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>