UNPKG

@zm17671443092/my-js-package

Version:

A simple JavaScript package for demonstration purposes.

12 lines 566 B
const getFormattedDate = () => { // 创建Date对象获取当前时间 const currentDate = new Date(); // 获取年、月、日 const year = currentDate.getFullYear(); const month = currentDate.getMonth() + 1; // 注意月份是从0开始计数,所以要加1 const day = currentDate.getDate(); // 拼接成想要的日期格式字符串,这里以"年-月-日"为例 return formattedDate = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`; } console.log(getFormattedDate()); module.exports = getFormattedDate;