0

I have function where I convert local time to UTC time, it works fine locally but when i deploy app on aws, it is no longer working

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;

and this is where I use this module

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,
  });
Medlide
  • 21
  • 2

1 Answers1

0

Using this will convert local time to UTC

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

You can also check this Moment Js UTC to Local Time

Prabhakaran
  • 3,900
  • 15
  • 46
  • 113