`How to convert dates correctly?
W
W
WarriorKodeK2021-10-21 15:59:16
JavaScript
WarriorKodeK, 2021-10-21 15:59:16

How to convert dates correctly?

Hello.
I have a dynamic string like:

const dateString = `${formattedCurrentDate} ${timeSlot?.startTime}`; -> `2021-10-21 13:30`


I run it through new Date() In the browser, everything works fine, but I do it on the backend, and it jumps to the console
const currentTimeSlotDate = new Date(dateString);
console.log(currentTimeSlotDate); -> 2021-10-21T13:30:00.000Z


If we go to the browser and enter , we will be givenconsole.log(new Date("2021-10-21T13:30:00.000Z"))
Thu Oct 21 2021 16:30:00 GMT+0300 (Eastern European Summer Time)


And you need
Thu Oct 21 2021 13:30:00 GMT+0300 (Eastern European Summer Time)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2021-10-21
@WarriorKodeK

Date.toString()

A
Alexander, 2015-12-31
Bass

More correctly:
int a = (editText1.getText() == null)?0:Integer.parseInt(editText1.getText().toString());
int b = (editText2.getText() == null)?0:Integer.parseInt(editText2.getText().toString());
textView.setText(Integer.toString(a + b));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question