anxiao_web/public/js/timestamp.js

81 lines
2.3 KiB
JavaScript

//获取当天
function getCurrData(){
var currentTime = new Date();
var year = currentTime.getFullYear();
var getMonth = (currentTime.getMonth()) + 1;
var getDate = currentTime.getDate();
if(getMonth < 10) {
getMonth = "0" + getMonth;
}
if(getDate < 10) {
getDate = "0" + getDate;
}
return year + "-" + getMonth + "-" + getDate;
}
function getWeekDate() {
var weeks = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
var now = new Date();
var day = now.getDay();
var week = weeks[day];
return week;
}
//秒装换成时间
function timestampFormatTime(timestamp){
var currentTime = new Date(timestamp);
var year = currentTime.getFullYear();
var getMonth = (currentTime.getMonth()) + 1;
var getDate = currentTime.getDate();
var getHours = currentTime.getHours();
var getMinutes = currentTime.getMinutes();
var getSeconds = currentTime.getSeconds();
if(getMonth < 10) {
getMonth = "0" + getMonth;
}
if(getDate < 10) {
getDate = "0" + getDate;
}
if(getHours < 10) {
getHours = "0" + getHours;
}
if(getMinutes < 10) {
getMinutes = "0" + getMinutes;
}
if(getSeconds < 10) {
getSeconds = "0" + getSeconds;
}
return year + "-" + getMonth + "-" + getDate + " " + getHours + ":" + getMinutes + ":" + getSeconds;
}
//获取当天的时间2021-11-12 14:12:12
function getCurrentTimeM(){
var currentTime = new Date();
var year = currentTime.getFullYear();
var getMonth = (currentTime.getMonth()) + 1;
var getDate = currentTime.getDate();
var getHours = currentTime.getHours();
var getMinutes = currentTime.getMinutes();
var getSeconds = currentTime.getSeconds();
if(getMonth < 10) {
getMonth = "0" + getMonth;
}
if(getDate < 10) {
getDate = "0" + getDate;
}
if(getHours < 10) {
getHours = "0" + getHours;
}
if(getMinutes < 10) {
getMinutes = "0" + getMinutes;
}
if(getSeconds < 10) {
getSeconds = "0" + getSeconds;
}
return year + "-" + getMonth + "-" + getDate + " " + getHours + ":" + getMinutes + ":" + getSeconds;
}
export {getCurrData,timestampFormatTime,getWeekDate,getCurrentTimeM}