const REGEX = /(\d{4})-(\d{2})-(\d{2})T(\d {2}) : (\d{2}) : (\d{2}) /
export const formattime = (val, format)+ ={
if (val) {
/**
* @instructions If it is not a timestamp format and contains the character '-' then '-' replace '-' with '/' && delete the decimal point and subsequent digits
* @reason '-' replace '-' with '/' && delete the decimal point and the following number because the Safari browser only supports '/' separated time formats
*/
if (val.toString(). indexOf ('-') > 0) {
val = val. Replace (/t/g, "). Replace (/\.[ \d]{3}z/, "). Replace (/(-)/g, '/'); //Replace '-' with '/'
val = val. Slice (0, Val. ) indexOf (".")); //delete the decimal point and subsequent digits
}
Let date = new date(val);
Date. sethours (date. getHours () + 8);
const [Whole, yy, MM, DD, hh, MM, ss] = date.toisostring (). Match (REGEX);
const Year = new Date (). getFullYear ();
const Month = new Date (). GetMonth () + 1;
Const Dates = new Date (). GetDate ();
if (format) {
return format
. Replace (' yyyy ', yy)
. Replace (' yy ', Yy.slice (2))
. Replace (' mm ', mm)
. Replace (' DD ', DD)
. Replace (' hh ', hh)
. Replace (' mm ', mm)
. Replace (' SS ', ss)
} else {
return [yy, MM, Dd].join('-') + ' + [hh, MM, SS]. Join (': ');
}
} else {
return '--';
}
}
JS format time (support applet, compatible with iOS)