js日期格式化(yy-mm-dd和yy-mm-dd hh:mm:ss)

/**

  • 时间格式化
  • 将 2020-09-23T11:54:16.000+0000 格式化成 2020-09-23
  • @param datetime 日期格式
    */
    export function format (datetime) {
    return formatWithSeperator(datetime, ‘-‘, ‘:’)
    }

第一种:yy-mm-dd
/**

  • 时间格式化
  • 将 2019-01-01T12:00:00.000+0000 格式化成类似 2019-01-01
  • datetime:需要格式化的时间
  • dateSeprator:时间分隔符
  • @param datetime 国际化日期格式
    /
    export function formatWithSeperator (datetime, dateSeprator, timeSeprator) {
    if (datetime != null) {
    const dateMat = new Date(datetime)
    const year = dateMat.getFullYear()
    const month = dateMat.getMonth() + 1
    const day = dateMat.getDate()
    const timeFormat = year + dateSeprator + month + dateSeprator + day
    return timeFormat
    }
    }
    第二种:yy-mm-dd hh:mm:ss
    /
    *
  • 时间格式化
  • 将 2019-01-01T12:00:00.000+0000 格式化成类似 2019-01-01 12:00:00
  • 可以指定日期和时间分隔符
  • @param datetime 国际化日期格式
    */
    export function formatWithSeperator (datetime, dateSeprator, timeSeprator) {
    if (datetime != null) {
    const dateMat = new Date(datetime)
    const year = dateMat.getFullYear()
    const month = dateMat.getMonth() + 1
    const day = dateMat.getDate()
    const hh = dateMat.getHours()
    const mm = dateMat.getMinutes()
    const ss = dateMat.getSeconds()
    const timeFormat = year + dateSeprator + month + dateSeprator + day + ‘ ‘ + hh + timeSeprator + mm + timeSeprator + ss
    return timeFormat
    }
    }
© 版权声明
THE END
如果内容对您有所帮助,就支持一下吧!
点赞0 分享
西安战神娱乐的头像 - 宋马
评论 抢沙发

请登录后发表评论

    暂无评论内容