screenFront/src/utils/time.ts

42 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-05-12 08:41:33 +00:00
/*
* @FilePath: \daping\src\utils\time.ts
* @Author:
* @文件版本: V1.0.0
* @Date: 2023-02-07 13:43:31
* @Description:
*
* 版权信息 : 2023 by ${}, All Rights Reserved.
*/
export function gettime(data=null){
var time
if(data){
time = new Date(data);
}else{
time = new Date();
}
var year = time.getFullYear();
// 1月到12月(0-11)
var month = time.getMonth()+1;
var dates = time.getDate();
// 周日-周六(0-6) 刚好对应数字下标
var day = time.getDay();
var arr = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
var hours:any = time.getHours();
var minutes:any = time.getMinutes();
var seconds:any = time.getSeconds();
// 小于10分钟前面补零
if (hours < 10) hours = "0" + hours;
if (minutes < 10) minutes = "0" + minutes;
if (seconds < 10) seconds = "0" + seconds;
return year + "-" + month + "-" + dates + " "+hours+':'+minutes+':'+seconds+' '+arr[day];
}
export function clacendTime(endtime,nowtime){
let newDate=Math.abs( endtime-nowtime)
var day=Math.floor(newDate/1000/60/60/24)
var h=Math.floor(newDate/1000/60/60%24)
var m=Math.floor(newDate/1000/60%60)
var s=Math.floor(newDate/1000%60)
return day+'天'+h+'时'+m+'分'+s+'秒'
}