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

206
Views
How to get only the date part of GMT in JavaScript?

Here's my date string:

2022-07-20T11:34:39

And here's my code to get GMT:

new Date('2022-07-20T11:34:39').toGMTString()
// prints this
// Wed, 20 Jul 2022 07:04:39 GMT

However, I only need the date part. Wed, 20 Jul 2022. I know I can use substring or regex or split etc. to extract it.

Is there any solution to achieve this without those tricks?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

First of all toGMTString() is depracated:

Note: toGMTString() is deprecated and should no longer be used. It remains implemented only for backward compatibility; please use toUTCString() instead.

You are looking for toDateString():

const res = new Date('2022-07-20T11:34:39').toDateString()
console.log(res)

Or more configurable toLocaleDateString():

const options = {
  weekday: 'short',
  year: 'numeric',
  month: 'short',
  day: 'numeric'
};
const res = new Date('2022-07-20T11:34:39').toLocaleDateString('en-US', options)
console.log(res)

about 4 years ago · Santiago Trujillo Report

0

use Intl.DateTimeFormat

const dateFormatter = new Intl.DateTimeFormat('en-GB', {
  year: 'numeric',
  month: 'long',
  day: 'numeric',
  weekday: 'short'
})

const dateFormatter2 = new Intl.DateTimeFormat('en-GB', {
  dateStyle: 'full'
})

const cdate = new Date()

console.log(dateFormatter.format(cdate));
console.log(dateFormatter2.format(cdate));

about 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!