likes
comments
collection
share

【工具moment】:utc time 和 local time 进行互相转换

作者站长头像
站长
· 阅读数 63

背景

在浏览器端,当我们做国际化项目的时候,如何使用moment进行utc time 和 local time 进行转换呢

工具

moment

代码

import moment from 'moment'

export function utcToLocal(date){
const format ='YYYY-MM-DD HH:mm:ss'
return moment.utc(date).local().format(format);
}

export function localToUtc(date){
    const format ='YYYY-MM-DD HH:mm:ss'
return moment(date,format).utc().format(format);
}
转载自:https://juejin.cn/post/7171695450355925023
评论
请登录