// 时分
getCurrentTime:function() {
var now = new Date();
var hours = now.getHours().toString().padStart(2, '0');
var minutes = now.getMinutes().toString().padStart(2, '0');
return hours + ':' + minutes;
},
// 年月日
getCurrentDate:function() {
var now = new Date();
var year = now.getFullYear();
var month = (now.getMonth() + 1).toString().padStart(2, '0');
var day = now.getDate().toString().padStart(2, '0');
return year + '年' + month + '月' + day + '日';
},
//上午、下午、晚上
getCurrentTimeText:function() {
var currentTime = new Date();
var currentHour = currentTime.getHours();
var currentMinute = currentTime.getMinutes();
var period;
if (currentHour < 12) {
period = "上午";
} else if (currentHour < 18) {
period = "下午";
} else {
period = "晚上";
};
return period + ' ' + currentHour + ':' + currentMinute;
},
js 分别实现获取时时时间、获取年、月、日以及上午、下午、晚上的时时时间
于 2023-06-25 10:31:07 首次发布