ah_sz_gqj/src/main/resources/static/js/commonUtils.js

102 lines
3.5 KiB
JavaScript
Raw Normal View History

2024-07-17 09:44:55 +08:00
// 格式化日对象
const getNowDate = () => {
var date = new Date();
var sign2 = "-";
var year = date.getFullYear() // 年
var month = date.getMonth() + 1; // 月
var day = date.getDate(); // 日
var hour = date.getHours(); // 时
var minutes = date.getMinutes(); // 分
var seconds = date.getSeconds() //秒
var weekArr = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期天'];
var week = weekArr[date.getDay()];
// 给一位数的数据前面加 “0”
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (day >= 0 && day <= 9) {
day = "0" + day;
}
if (hour >= 0 && hour <= 9) {
hour = "0" + hour;
}
if (minutes >= 0 && minutes <= 9) {
minutes = "0" + minutes;
}
if (seconds >= 0 && seconds <= 9) {
seconds = "0" + seconds;
}
return year + "-" + month + "-" + day + "-" + hour + sign2 + minutes + sign2 + seconds;
}
function getTime() {
var today = new Date();
// 获取年、月、日、时、分、秒
var year = today.getFullYear();
var month = today.getMonth() + 1; // 月份是从 0 开始计数的需要加1
var day = today.getDate();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
// 格式化输出
var formattedTime = year + "" +
(month < 10 ? "0" : "") + month + "" +
(day < 10 ? "0" : "") + day + "" +
(hours < 10 ? "0" : "") + hours + "" +
(minutes < 10 ? "0" : "") + minutes + "" +
(seconds < 10 ? "0" : "") + seconds;
return formattedTime;
}
/**
* 获取当日时间
*/
function getNowTime() {
var nowDate = new Date();
var year = nowDate.getFullYear();
var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) :
nowDate.getMonth() + 1;
var day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
var dateStr = year + "-" + month + "-" + day;
return dateStr;
}
// 获取当前日期 后几天的日期
function fun_date(aa) {
//time1表示当前时间
let date1 = new Date(), time1 = date1.getFullYear() + "-" + (date1.getMonth() + 1) + "-" + date1.getDate();
let date2 = new Date(date1);
date2.setDate(date1.getDate() + aa);
let month = date2.getMonth() + 1 < 10 ? "0" + (date2.getMonth() + 1) :
date2.getMonth() + 1;
let day = date2.getDate() < 10 ? "0" + date2.getDate() : date2.getDate();
let time2 = date2.getFullYear() + "-" + month + "-" + day;
return time2;
}
function formatSeconds(value) {
let hh = parseInt(value / 3600);
if (hh < 10) hh = "0" + hh;
let mm = parseInt((value - hh * 3600) / 60);
if (mm < 10) mm = "0" + mm;
let ss = parseInt((value - hh * 3600) % 60);
if (ss < 10) ss = "0" + ss;
let length = hh + ":" + mm + ":" + ss;
if (value > 0) {
return length;
} else {
return "00:00:00";
}
2024-07-25 13:00:29 +08:00
}
/*设置审核状态字体颜色*/
function setAuditStatus(value){
if(value === '待试验' || value === '待提交' || value === '待审核' || value === '待审批' || value === '待审阅'){
return '<span style="color: #5778f3">'+value+'</span>';
}else if(value === '审阅不通过' || value === '审核不通过' || value === '审批不通过'){
return '<span style="color: #f1895b ">'+value+'</span>';
}else if(value === '试验完成'){
return '<span style="color: #C4C4C4">'+value+'</span>';
}
2024-07-17 09:44:55 +08:00
}