olympus-r-17plugins
Version:
A plugin of Olympus for 17zuoye.
41 lines (40 loc) • 1.27 kB
JavaScript
/**
* @author Raykid
* @email initial_r@qq.com
* @create date 2018-02-07
* @modifier yuan.ping
* @modify date 2018-06-21
*
* 日期时间工具集
*/
/**
* 格式化日期和时间
* @param timestamp 时间戳/1000
* @param format 格式,如"yyyy-MM-dd-hh-mm-ss"
* @returns {string} Formated Time
*/
export function getFormattedDate(timestamp, format) {
if (format === void 0) { format = "yyyy-MM-dd hh:mm:ss"; }
var tempDate = new Date();
if (timestamp != 0) {
tempDate.setTime(timestamp * 1000);
}
var o = {
"M+": tempDate.getMonth() + 1,
"d+": tempDate.getDate(),
"h+": tempDate.getHours(),
"m+": tempDate.getMinutes(),
"s+": tempDate.getSeconds(),
"q+": Math.floor((tempDate.getMonth() + 3) / 3),
"S": tempDate.getMilliseconds() //millisecond
};
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (tempDate.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
}
}
return format;
}