diff --git a/fir_client/src/utils/format.js b/fir_client/src/utils/format.js new file mode 100644 index 0000000..e4e5037 --- /dev/null +++ b/fir_client/src/utils/format.js @@ -0,0 +1,22 @@ +module.exports =function dateFormat(format, date=null) { + if(!date){ + date = new Date() + } + const args = { + "M+": date.getMonth() + 1, + "d+": date.getDate(), + "h+": date.getHours(), + "m+": date.getMinutes(), + "s+": date.getSeconds(), + "q+": Math.floor((date.getMonth() + 3) / 3), + "S": date.getMilliseconds() + }; + if (/(y+)/.test(format)) + format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length)); + for (let i in args) { + let n = args[i]; + if (new RegExp("(" + i + ")").test(format)) + format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? n : ("00" + n).substr(("" + n).length)); + } + return format; +}