js将美式日期格式转为国内标准格式(将 09/19/1999 12:12:12 转为 1999-09-19 12:12:12)

在公用文件util.js中新增处理方法,在需要使用的页面引入调用该方法,入参为美式日期( 09/19/1999 12:12:12 )


// 将美式日期时间格式转为国内标准日期时间(MM/DD/YYYY hh:mm:ss 转为 YYYY-MM-DD hh:mm:ss)
export function dateConversion(day) {
  if (day) {
    // 获取年
    let year = day.slice(0,10).split('/')[2];
    // 获取月份,日份拼接完整日期
    let date = year + '-' + day.slice(0,5).split('/').join('-') + day.slice(10);
    return date;
  };
  return "";
}
// 将2020-11-12T09:42:16.000+08:00格式转为2020-11-12 09:42
const formatDateTime = (dateString) => {
  const date = new Date(dateString)
  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 formattedDate = `${year}-${month}-${day} ${hours}:${minutes}`
  return formattedDate
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值