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

245
Views
Javascript - Why time in ISO8601 format shows in 2 different formats at console.log?

I have date in ISO8601 format, e.g. '2021-01-01T00:00:00.000Z'. I try console.log it as part of string and as variable - I get two different results:

2021-01-01T00:00:00.000Z - when I show it as variable

Fri Jan 01 2021 01:00:00 GMT+0100 (Central European Standard Time) - when I show it as part of string

How could I show date in ISO8601 format '2021-01-01T00:00:00.000Z' as part of string?

let date = new Date(2021, 0, (1 + (1 - 1) * 7), 1);

console.log('Show as variable: ', date);
console.log(`Show as part of string: ${date}`);

edited: set proper date format.

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

0

My guess is that it depends on each runtime's implementation of console.log. The template literal (your second example) would do the interpolation of the template before passing the whole thing to console.log, hence it will be a string already when logging (and it would use the same value as date.toString()), whereas the first variant passes a string literal and then an object, which isn't necessarily a string as well (and it's up to the console to decide how to display it; think of how you usually have more convenient display options for arrays, objects and so on).

Chrome seems to not care and shows both variants the same, whereas Firefox shows the first one as a Date instance. Node's CLI kind of behaves like Firefox and shows them differently, but doesn't show that the type is Date.

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!