获取给定毫秒时间的当前分钟、小时、日、周、月、年
function getDateInfo(milliseconds) {
const date = new Date(milliseconds);
const minutes = date.getMinutes();
const hours = date.getHours();
const days = date.getDate();
const weeks = date.getDay();
const months = date.getMonth() + 1;
const years = date.getFullYear();
return {
minutes: minutes,
hours: hours,
days: days,
weeks: weeks,
months: months,
years: years
};
}
const milliseconds = 1633512786790;
const dateInfo = getDateInfo(milliseconds);
console.log(`当前分钟: ${dateInfo.minutes}`);
console.log(`当前小时: ${dateInfo.hours}`);
console.log(`当前日: ${dateInfo.days}`);
console.log(`当前周: ${dateInfo.weeks}`);
console.log(`当前月: ${dateInfo.months}`);
console.log(`当前年: ${dateInfo.years}`);
{
"name": "getDateInfo",
"description": "获取给定毫秒时间的当前分钟、小时、日、周、月、年",
"parameters": {
"milliseconds": "1633512786790"
},
"returns": "object",
"category": "Time and Date",
"version": 1
}
领取专属 10元无门槛券
手把手带您无忧上云