zoukankan      html  css  js  c++  java
  • 时间形式的转换

    关于时间

    获取当前时间:

    new Date()                           //  Fri Jan 22 2021 14:40:45 GMT+0800 (中国标准时间)
    
    new Date().getFullYear()     //  2021
    
    new Date().getMonth()        //  0        (获取月时记得 +1 )
    
    new Date().getDate()          //  22
    
    new Date().getHours()        //  14
    
    
    new Date().getMinutes()      //  43
    
    new Date().getSeconds()     //   39
    
    new Date().getMilliseconds()  //  217     (毫秒)
    
    new Date().getDay()              //  5        (星期)    
    
    new Date().getTimezoneOffset()    //  -480        与格林威治时间的时间差  (单位:分钟)

    其他时间形式 转换为 时间戳

    new Date().getTime()           //  1611297667687

     

      时间戳  转换成 其他时间形式 

       插件   dayjs:  https://dayjs.fenxianglu.cn/

    方法:

     dateFilter(time, type) {
          let date = new Date(time * 1000)
          let year = date.getFullYear()
          let month = date.getMonth() + 1
          let day = date.getDate()
          let hours = date.getHours()
          let minutes = date.getMinutes()
          let second = date.getSeconds()
          let format = (value) => {
            return value >= 10 ? value : '0' + value
          }
          let result
          switch (type) {
            case 0: // 01-05
              result = `${format(month)}月${format(day)}日`
              break
            case 1: // 11:12
              result = `${format(hours)}-${format(minutes)}`
              break
            case 2: // 2015-01-05
              result = `${year}-${format(month)}-${format(day)}`
              break
            case 3: // 2015-01-05 11:12
              result = `${year}-${format(month)}-${format(day)}  ${format(
                hours
    
     )}:${format(minutes)}`
              break
            case 4: // 2015.01.05 11:12
              result = `${year}.${month}.${day}  ${hours}:${minutes}`
              break
            case 5:
              result = `${year}年${format(month)}月${format(day)}日${format(
                hours
    
     )}时${format(minutes)}分`
            case 6: // 2015-01-05 11:12:06
              result = `${year}-${format(month)}-${format(day)}  ${format(
                hours
              )}:${format(minutes)}:${format(second)}`
              break
            case 7:
              result = `${year}-${format(month)}`
              break
            case 8:
              result = `${year}年${format(month)}月`
              break
            case 9: // 2015-01-05 11:12:06:32
              result = `${year}-${format(month)}-${format(day)}  ${format(
                hours
              )}:${format(minutes)}:${format(second)}`
              break
          }
          return result
        },
  • 相关阅读:
    CSS overflow 隐藏属性
    CSS visibility 隐藏属性
    多线程中的detach
    多线程中join的解释(转)
    lib 和 dll 的区别、生成以及使用详解:(包括变量,函数,类导出3种情形)(转)
    堆和栈的区别
    ZMQ相关
    不同类型的指针加减(就是向前或向后移动)[转]
    memset函数及其用法,C语言memset函数详解
    zmq中的router和dealer
  • 原文地址:https://www.cnblogs.com/dandanyajin/p/14313677.html
Copyright © 2011-2022 走看看