[Solved] how to get date of my localtime like 2020-03-11T02:59 with javascript [duplicate]


You can change the timezone with the offset at the end of the date string (e.g. -05:00).

And then create the date string you want using get functions.

You will need to pad the month, day, hour and minutes. However, the .get (eg .getMonth) functions return numbers, so you will also have to convert them to strings.

For example: event.getMonth().toString().padStart(2,0);

event is your date object.

.getMonth() returns the numeric value of the month of your date object

.toString() converts that number to a string value

.padStart(2,0) will add zeros to the front of the string if it is less than 2 characters.

// Set the date with timezone offset
let event = new Date("2020-03-11T02:59:00-08:00");

// Format your string
let newEvent = `${event.getFullYear()}-${event.getMonth().toString().padStart(2,0)}-${event.getDate().toString().padStart(2,0)}T${event.getHours().toString().padStart(2,0)}:${event.getMinutes().toString().padStart(2,0)}`;

console.log(newEvent);

2

solved how to get date of my localtime like 2020-03-11T02:59 with javascript [duplicate]