would something like this make sense to be a part of Espruinos Date() class ?
Date.prototype.toDateString = function(format) {
/*
yyyy Year, long form (e.g., 2016).
mm Numeric month, a number from 1 to 12.
dd Day, a number from 1 to 31.
HH Hour, a number from 0 to 23.
MM Minutes, a number from 0 to 59.
ss Seconds, a number from 0 to 61 (59 plus a maximum of two leap seconds).
*/
if (format) {
// yyyy
var YYYY = this.getFullYear().toString();
format = format.replace("yyyy",YYYY);
// mm
var mm = (this.getMonth() + 1).toString();
mm = mm.length > 1 ? mm : '0' + mm;
format = format.replace("mm",mm);
//dd
var dd = this.getDate().toString();
dd = dd.length > 1 ? dd : '0' + dd;
format = format.replace("dd",dd);
//HH
var HH = this.getHours().toString();
HH = HH.length > 1 ? HH : '0' + HH;
format = format.replace("HH",HH);
//MM
var MM = this.getMinutes().toString();
MM = MM.length > 1 ? MM : '0' + MM;
format = format.replace("MM",MM);
//SS
var SS = this.getSeconds().toString();
SS = SS.length > 1 ? SS : '0' + SS;
format = format.replace("SS",SS);
return format;
}
else {
format = this.toString();
}
};
>Date().toDateString();
="Tue Jul 19 2016 08:13:46 GMT+0000"
>Date().toDateString("yyyy.mm.dd HH:MM:SS");
="2016.07.19 08:13:12"
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
would something like this make sense to be a part of Espruinos Date() class ?