Salin kode kode sebagai berikut:
/**
* Formulasi objek waktu;
*/
Date.prototype.format = function (format) {
/*
* misalnya: format = "yyyy-mm-dd hh: mm: ss";
*/
var o = {
"M +": this.getmonth () + 1, // bulan
"D+": this.getDate (), // day
"H+": this.getHours (), // jam
"M+": this.getMinutes (), // menit
"S+": this.getSeconds (), // kedua
"q +": math.floor ((this.getmonth ()) + 3), // kuartal
"S": this.getMilliseconds ()
// milidetik
}
if (//y+)/.test (format)) {{
format = format.replace (regexp. $ 1, (this.getlyear () + "")
.substr (4 -regexp. $ 1.length);
}
untuk (var k in o) {
if (regexp baru ("(" + k + ")). Test (format) {
Format = format.replace (regexp. $ 1, regexp. $ 1.length == 1? O [k]
: ("00" + o [k]).
}
}
Format pengembalian;
}
Salin kode kode sebagai berikut:
var sekarang = tanggal baru ().
Salin kode kode sebagai berikut:
Tanggal baru ().