0

I am trying to get this month's first date. When I use this code in online compiler, I get the expected date like 2023-02-01. When I use it in my code and see this output in console, it shows the date as 2023-01-31.

I don't know why it is working fine in online compiler, but causing problem in console.log. I want to know the reason for this

This is the code I used:

let date = new Date();
let first_date = new Date(date.getFullYear(), date.getMonth(), 1).toISOString().slice(0,10);

Below, I have attached output data for both online compiler and console.log:

This is online compiler output

console output

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Mokey D Luffy
  • 266
  • 2
  • 13

0 Answers0