dates are not same in server and client(dayjs)

currentDate = new Date();
const options = { timeZone: "Asia/Kolkata" };
const indianDateAndTime = currentDate.toLocaleString("en-US", options);
const indianDate = indianDateAndTime.substring(0, 9) as string;
const date = dayjs.tz(indianDate, "Asia/Kolkata");
const minDate = date.add(minReminderRange, "day").toDate();

const maxDate = date.add(maxReminderRange, "day").toDate();
console.log(maxDate.toISOString(), minDate.toISOString());
currentDate = new Date();
const options = { timeZone: "Asia/Kolkata" };
const indianDateAndTime = currentDate.toLocaleString("en-US", options);
const indianDate = indianDateAndTime.substring(0, 9) as string;
const date = dayjs.tz(indianDate, "Asia/Kolkata");
const minDate = date.add(minReminderRange, "day").toDate();

const maxDate = date.add(maxReminderRange, "day").toDate();
console.log(maxDate.toISOString(), minDate.toISOString());
this is giving output in client as 2023-08-07T13:00:00.000Z 2023-07-12T13:00:00.000Z output in server 2023-08-07T18:30:00.000Z 2023-07-12T18:30:00.000Z can anyone tell me why it is happening
8 Replies
Neto
Neto12mo ago
timezone also, you can check the relative time, in seconds, and check if they are the same
pradeep
pradeep12mo ago
millisecond in client 1691413200000 1689166800000 millisecond in server 1691433000000 1689186600000 they are not same
Neto
Neto12mo ago
js dates are a mess
pradeep
pradeep12mo ago
can please help me how can solve this problem
Neto
Neto12mo ago
you either compensate the date for both of them to use central time or one of them will have to sync with the other
pradeep
pradeep12mo ago
how can i do that?
Neto
Neto12mo ago
from the looks of it the difference is 5 hours just add 5 hours in one side, or remove from the other
pradeep
pradeep12mo ago
Okay thank you