I'm making a Discord bot that I want to have a reward that you can claim once per day, and if you've already claimed it, it tells you how much time left. I've made the function that converts milliseconds into a readable format, but somehow using Date objects isn't working. Here is my code to get the timestamp in ms of the next claim time:
const nextdate = new Date(oldms + 86400000); // oldms is the miliseconds timestamp of the last claim time, this adds 24 hours to it.
// The next two lines are to set it to 00:00:00 so it can show the time until properly.
const regex = new RegExp(" ..:..:.. GMT");
const realnextdate = new Date(nextdate.toUTCString().replace(regex, ""));
return realnextdate.getTime();
But when I run it, the time is always the day before the next claim, so the remaining time is negative. Can anyone tell me how I can get the actual timestamp of the next midnight?
Edit 1: My server is in UTC + 2 timezone, if that changes anything. (Optimally, it should not.)