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

293
Views
How to convert zulu time to UTC +01:00 without moment

Hi i have a date that arrive with this format 2020-05-25T20:11:38Z, and i need to convert to 2020-05-25T21:11:38+01:00. In my project is not installed moment.js is a big project, and the masters don't use it. is there some where to make this change?

I have the timeZone for every zone. I know that there is options like this getTimezoneOffset(); And i did find in stackoverflow, but i didn't find any response in javascript to change zulu to utc with offset.

Thanks for your indications

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

0

The format "2020-05-25T20:11:38Z" is a common standard ISO 8601 format, it is also produced by the default Date.prototype.toString method, however it's only with a UTC (+0) offset.

The above ISO 8601 format is reliably parsed by reasonably current built–in parsers (some very old implementations won't parse it correctly), so to get a Date object:

let date = new Date('2020-05-25T20:11:38Z');

Formatting it for a fixed +1 offset can done by adjusting the Date for the offset then formatting it as required by leveraging the default toISOString method, e.g.

// Initial timestamp
let s = '2020-05-25T20:11:38Z'

// Convert s to a Date
let d = new Date(s);
// Show that it's the same date
console.log(`Initial value: ${s}\n` +
            `Parsed value : ${d.toISOString()}`);

// Create a new date with 1 hour added as 3,600,000 milliseconds
let e = new Date(d.getTime() + 3.6e6);

// Format and manually modify the offset part
let timestamp = e.toISOString().replace('Z','+01:00');
console.log(`Adjusted timestamp: ${timestamp}`);

// Parse back to date
console.log(`Parsed to a Date  : ${new Date(timestamp).toISOString()}`);

The resulting timestamp can be parsed back to a Date that represents the same instant in time as the original string (last line).

Note that the adjusted Date is only created for the sake of formatting the timestamp, it shouldn't be used for anything else.

If, on the other hand, you want a general function to format dates as ISO 8601 with the local offset, there is likely an answer at Javascript date format like ISO but local that suits. If so, then this is a duplicate, e.g. this answer or this one.

Also, there are a number of libraries that will allow specifying the formatting and timezone as separate parameters, so consider using one if you're going to do a lot of date formatting or manipulation.

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!