华为鸿蒙开发笔记1:时间戳

  let date: Date = new Date();
    //获取年份
    const year = date.getFullYear();
    //获取月份
    const month = String(date.getMonth() + 1).padStart(2, '0');
    //获取星期
    const day = String(date.getDate()).padStart(2, '0');
    // 获取小时
    const hours = String(date.getHours()).padStart(2, '0');
    // 获取分钟
    const minutes = String(date.getMinutes()).padStart(2, '0');
    // 获取秒数
    const seconds = String(date.getSeconds()).padStart(2, '0');
    let time =  `${year}年${month}月${day}日 ${hours}:${minutes}:${seconds}`
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容