You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
high-mini/Utils/js/date.js

58 lines
1.6 KiB

const isNullOrEmpty = function(val) {
if (val == null || val == "" || typeof(val) == undefined) {
return true;
} else {
return false;
}
}
const timeFormat = (value, format) => {
let date = new Date(value);
let y = date.getFullYear();
let m = date.getMonth() + 1;
let d = date.getDate();
let h = date.getHours();
let min = date.getMinutes();
let s = date.getSeconds();
let result = "";
if (format == undefined) {
result = `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d} ${
h < 10 ? "0" + h : h
}:${min < 10 ? "0" + min : min}:${s < 10 ? "0" + s : s}`;
}
if (format == "yyyy-mm-dd hh:mm:ss") {
result = `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d} ${h < 10 ? "0" + h : h}:${min < 10 ? "0" + min : min}:${s < 10 ? "0" + s : s}`;
}
if (format == "yyyy-mm-dd hh:mm") {
result = `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d} `;
}
if (format == "yyyy-mm-dd") {
result = `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d}`;
}
if (format == "yyyy-mm") {
result = `${y}-${m < 10 ? "0" + m : m}`;
}
if (format == "mm-dd") {
result = ` ${mm < 10 ? "0" + mm : mm}:${ddmin < 10 ? "0" + dd : dd}`;
}
if (format == "hh:mm") {
result = ` ${h < 10 ? "0" + h : h}:${min < 10 ? "0" + min : min}`;
}
if (format == "yyyy") {
result = `${y}`;
}
return result;
};
// {{date|isNullOrEmpty}}
// {{date|timeFormat('yyyy-mm-dd')}}
// {{date|timeFormat('yyyy-mm')}}
// {{date|timeFormat('hh:mm')}}
// {{date|timeFormat('yyyy')}}
// {{date|timeFormat}}
export {
isNullOrEmpty,
timeFormat
}