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

748
Views
remove the local timezone from a date in javascript?

I was wondering if I can remove the timezone from the date using javascript? I get the datetime on a json format, now I want to set it back but it returns more info of what I actually want/need.

What I have now is:

var d = new Date();
d.setTime(1432851021000);
document.write(d);

and the output is something like this:

Thu May 28 2015 16:10:21 GMT-0600 (CST)

Id like to show only until the hour, and remove GMT-0600 (CST).

I know javascript takes that depending on the current user's timezone, which is a problem, because the information could be saved on different countries.

I am trying to avoid to create the format using something like:

d.date() + "/" + d.month()...etc

Is there a better solution for this?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

I believe d.toDateString() will output the format you're looking for.

var d = new Date();
d.setTime(1432851021000);
d.toDateString(); // outputs to "Thu May 28 2015"
d.toGMTString(); //outputs to "Thu, 28 May 2015 22:10:21 GMT"

Or even d.toLocaleString() "5/28/2015, 6:10:21 PM"

There are lots of methods available to Date()

over 4 years ago · Santiago Trujillo Report

0

Since the part you want will always has fixed length you can use:

d.toString().slice(0, 24)

jsfiddle

over 4 years ago · Santiago Trujillo Report

0

Using moment

moment().utcOffset(0, true).format()

From Javascript Date

var date = new Date();
Tue Sep 06 2021 00:00:00 GMT+0200

var isoDate = date.toISOString()
'2021-09-05T22:00:00.000Z'

var clearUTCDate = moment(date).utcOffset(0, true).format() 
'2021-09-06T00:00:00Z'
over 4 years ago · Santiago Trujillo 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!