javascript - how do you get current day's starting time and the most current time in milliseconds -
need curent time , 00:00 in morning in milliseconds? need automatically every day, current starting morning (00:00:00) , current time in milliseconds? has done this?
this works :
function milliseconddiff(mydate) { var midnightday = mydate.getutcdate(); var midnightmonth = mydate.getutcmonth() + 1; var midnightyear = mydate.getutcfullyear(); var midnightmilliseconds = new date(midnightyear + '/' + midnightmonth + '/' + midnightday).gettime(); return new date().gettime() - midnightmilliseconds; } var millissincemidnight = milliseconddiff(new date()); console.log(millissincemidnight + ' ms'); console.log((millissincemidnight / 1000) + ' s'); console.log((millissincemidnight / (1000 * 60)) + ' min'); console.log((millissincemidnight / (1000 * 60 * 60)) + ' h');
Comments
Post a Comment