/**
* 获取星期
*/
function getWeekDate() {
var now = new Date();
var day = now.getDay();
var weeks = new Array(“星期日”, “星期一”, “星期二”, “星期三”, “星期四”, “星期五”, “星期六”);
var week = weeks[day];
return week;
}
/**
* 获取年月日
*/
function getNowFormatDate() {
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = ‘0’ + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = ‘0’ + strDate;
}
var currentdate = year + ‘年’ + month + ‘月’ + strDate + ‘日’;
return currentdate;
}
/**
* 获取时分秒
*/
function getHis() {
var myDate = new Date();
let hours = myDate.getHours();
let minutes = myDate.getMinutes();
let seconds = myDate.getSeconds();
if (hours < 10) {
hours = ‘0’ + hours;
}
if (minutes < 10) {
minutes = ‘0’ + minutes;
}
if (seconds < 10) {
seconds = ‘0’ + seconds;
}
return hours + “:” + minutes + ‘:’ + seconds
}
声明:
本文采用
BY-NC-SA
协议进行授权,如无注明均为原创,转载请注明转自
一颗大萝北
本文地址: JS获取年月日时分秒及星期几
本文地址: JS获取年月日时分秒及星期几