zoukankan      html  css  js  c++  java
  • 后台项目工具开发

     1 export function formatDate(time, fmt) {
     2     if (!time || time === '0') {
     3       return ''
     4     }
     5     let timeDate = new Date(+time)
     6     var options = {
     7       'M+': timeDate.getMonth() + 1,
     8       'd+': timeDate.getDate(),
     9       'h+': timeDate.getHours(),
    10       'm+': timeDate.getMinutes(),
    11       's+': timeDate.getSeconds()
    12     }
    13     if (/(y+)/.test(fmt)) {
    14       fmt = fmt.replace(RegExp.$1, (timeDate.getFullYear() + '').substr(4 - RegExp.$1.length))
    15     }
    16     for (var o in options) {
    17       if (new RegExp('(' + o + ')').test(fmt)) {
    18         fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (options[o]) : (('00' + options[o]).substr(('' + options[o]).length)))
    19       }
    20     }
    21     return fmt
    22   }
    23 
    24 
    25  dateFormat({agentStartTime, agentEndTime}) {
    26 //时间戳+需求
    27         let start = formatDate(agentStartTime, 'yyyy-MM-dd')
    28         let end = formatDate(agentEndTime, 'yyyy-MM-dd')
    29         if (start === '-' && end === '-') { return '-' }
    30         return `${start} 至 ${end}`
    31       },

    引用方式:

    import { formatDate } from "@/components/figure-keyframes/help.js"
    适用于:时间戳转化为具体时间
    1 /**
    2  * @param 获取n位的数字随机数
    3  */
    4 export const randomn = function(n) {
    5   if (n > 21) return null
    6   return parseInt((Math.random() + 1) * Math.pow(10, n - 1))
    7 }
     1 export const clone = function(val) {//深拷贝
     2   var xtype = getType(val)
     3   if (xtype === 'array') {
     4     var arr = []
     5     for (var i = 0; i < val.length; i++) {
     6       arr[i] = clone(val[i])
     7     }
     8     return arr
     9   } else if (xtype === 'object') {
    10     var obj = {}
    11     for (i in val) {
    12       if (val.hasOwnProperty(i)) {
    13         var value = val[i]
    14         obj[i] = value && value.nodeType ? value : clone(value)
    15       }
    16     }
    17     return obj
    18   }
    19   return val
    20 }
  • 相关阅读:
    deepin/uos和局域网其他机器无法ping通
    Ubuntu18.04完全卸载vscode
    批量拉取github组织或者用户的仓库
    vmware uos挂载windows共享目录
    清空容器另类方式
    time_t 时间格式化字符串
    条件变量condition_variable
    C++多维堆数组定义
    arm64 ubuntu18.04 bionic安装bcc tools
    win10下载编译chromium
  • 原文地址:https://www.cnblogs.com/lujunan/p/10468522.html
Copyright © 2011-2022 走看看