JS——生成时间戳的函数

生成时间戳:

1.Date.now();
2.new Date().getTime()

生成YYYYMMDDHHMMSSMiMiMi格式

// 根据时间生成yyyymmddhhmmss,用来下载图片命名
const generateTime = function () {
  const now = new Date();
  const time =
    now.getFullYear().toString() +
    (now.getMonth() + 1) +
    now.getDate() +
    now.getHours() +
    now.getMinutes() +
    now.getSeconds() +
    now.getMilliseconds();
  return time;
};
posted @ 2022-11-26 23:27  Pixel-hut  阅读(361)  评论(0)    收藏  举报