zoukankan      html  css  js  c++  java
  • js时间戳转化成日期格式

    前言:

    时间戳:1540460693,需转化成时间格式:2018/10/25

    // 时间戳转换日期格式
    function timeFormat(nS) {
      let date = new Date(parseInt(nS) * 1000) // 时间戳为10位需乘1000,为13位则不用
    
      let Y = date.getFullYear() //
      let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) //
      let D = date.getDate() < 10 ? '0' + date.getDate() + '' : date.getDate() + '' //
    
      let h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours() //
      let m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes() //
      let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds() //
    
      // 一个函数只能有一个return,以下仅做示例
      return Y + '-' + M + '-' + D // yyyy-mm-dd
      return Y + '-' + M + '-' + D + ' ' + h + ':' + m + ':' + 's' // yyyy-mm-dd hh:mm:ss
    
      return Y + '/' + M + '/' + D // yyyy/mm/dd
      return Y + '/' + M + '/' + D + ' ' + h + ':' + m + ':' + 's' // yyyy/mm/dd hh:mm:ss
    
    }
  • 相关阅读:
    JDK源码分析 – HashMap
    牛哄哄的celery
    redis数据库基础篇
    RPC的入门应用
    Python的常用模块
    消息队列之真知灼见
    面向对象编程(2)
    python3的C3算法
    面向对象编程(1)
    CRM项目之stark组件(2)
  • 原文地址:https://www.cnblogs.com/cathy1024/p/10304412.html
Copyright © 2011-2022 走看看