var MYDATE = new Date("2023/03/09 08:30:19").toISOString();
var CURDATE = Date();
const compareDates = (d1, d2) => {
let date1 = new Date(d1).getTime();
let date2 = new Date(d2).getTime();
let diff = date1 - date2;
console.log( convertMsToTime( diff ) )
};
function convertMsToTime(ms) {
const seconds = Math.floor(ms / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);
let DIFF;
if ( days > 0){ DIFF =+ days+" day/s " }
if ( hours > 0){ DIFF =+ hours+ " Hour/s " }
if ( minutes > 0){ DIFF =+ minutes+ " Minute/s " }
//if ( seconds > 0){ DIFF =+ seconds+ }
return DIFF;
}
function getTimeDifference() {
// Create a new Date object for the current date and time
const now = new Date();
// Convert the current date and time to UTC
const nowUtc = new Date(now.getTime() + now.getTimezoneOffset() * 60000);
// Create a new Date object for the specified date and time
const specified = new Date('2023-03-09T13:38:16');
// Calculate the difference between the two dates in milliseconds
const differenceMs = Math.abs(nowUtc - specified);
// Calculate the difference in days, hours, and minutes
const days = Math.floor(differenceMs / (1000 * 60 * 60 * 24));
const hours = Math.floor((differenceMs % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((differenceMs % (1000 * 60 * 60)) / (1000 * 60));
// Return the difference as an object
return { days, hours, minutes };
}
// Call the function and log the result to the console
console.log(getTimeDifference());
//console.log( compareDates(CURDATE, MYDATE) )
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.