问题描述
我在我的 react js 项目中使用了 moment-timezone。日期时间转换显示正确,但时刻时区没有 IST 数据 控制台中显示错误
import moment from "moment-timezone";
export function utcToDate() {
const zone_name = moment.tz.guess();
const timezone = moment.tz(zone_name).zoneName();
return moment(1607954125191).tz(timezone).format("MMM DD YYYY,hh:mm A");
}
解决方法
使用 zone_name 而不是 timezone
return moment(date).tz(zone_name).format("MMM DD YYYY,hh:mm A");