Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
Javascript local datetime into selected timezone

I have https://www.daterangepicker.com/ which outputs some datetimes.

If I am in timezone (device timezone) Europe/Kiev (GMT+3) the outputs will be in those timeszones. For example 27 June 2022 12:00:00 am GMT+3. (midnight) enter image description here

var output = 1656277200000;

I also have the user that selects a timezone for example user selects London (GMT+1).

var timezone = "Europe/London";

I want to convert that output unix time from 27 June 2022 12:00:00 am GMT+3 to the timezone of what the user selected, the London timezone: 27 June 2022 12:00:00 am GMT+1. That means the unix: 1656284400000

enter image description here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You would have to convert the timezone to an integer representing GMT. Then you subtract your timezone from theirs. You can convert the difference to milliseconds and add it to the original unix time. Example if your timezone is +5 and theirs is +7:

const myTimezone = 5;
const theirTimezone = 7;
const diffarance = theirTimezone - myTimezone; // set to + 2
const differenceMilliseconds = diffarance * 3600000;
const theirUnix = myUnix + differenceMilliseconds;

This also works if the the difference is negative.

about 4 years ago · Juan Pablo Isaza Report

0

You can try this way

// Without moment-timezone
new Date().toLocaleString("en-US", { timeZone: "America/New_York" });

// With moment-timezone
var moment = require("moment-timezone");
const today = new Date();
var timeGet = moment(today);
timeGet.tz("Asia/Karachi").format("ha z");
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!