【问题标题】:moment.utc() returning same time at awsmoment.utc() 在 aws 同时返回
【发布时间】:2022-01-16 19:34:38
【问题描述】:

我有将本地时间转换为 UTC 时间的功能,它在本地工作正常,但是当我在 aws 上部署应用程序时,它不再工作

import timezone from "geo-tz";
import moment from "moment-timezone";

const { find } = timezone;
function convertToUtc(time, lon, lat) {
  const timezone = find(lat, lon);

  const date = moment(time, "HHmm").tz(timezone[0]).utc().format("HH:mm");
  return date;
}

export default convertToUtc;

这就是我使用这个模块的地方

const user = await User.find({ chatID: res.chat.id });
  const utctime = utc(
    user[0].time,
    res.location.longitude,
    res.location.latitude
  );
  
  await User.find({ chatID: res.chat.id }).update({
    time: utctime,
    location: res.location,
  });

【问题讨论】:

    标签: node.js amazon-ec2 momentjs


    【解决方案1】:

    使用它会将本地时间转换为 UTC

    moment().utc().format()
    moment().utc().format('HH:mm')
    

    您也可以查看Moment Js UTC to Local Time

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-19
      • 2020-10-04
      • 2021-02-08
      • 2019-03-19
      • 2021-05-14
      • 2014-12-14
      • 2018-06-21
      • 2019-09-21
      相关资源
      最近更新 更多