This code compares 2 time - present time and a deadline time.
// Get current date/time
var now = new Date();
// Set up deadline date/time
var deadline = new Date(); //deadline is 1830hrs;
deadline.setHours(18);
deadline.setMinutes(30);
// Check if the current time is after the deadline
if( now > deadline ) {
console.log('after deadline');
}
else {
console.log('before deadline');
}
It works on my local machine where now
and deadline
are in the same timezone. What if the code is run on a server where the now
timezone can be different from the deadline
timezone to be compared? How to handle the situation when now
can be any timezone and deadline
is in, say, the Asia/HongKong timezone?
EDIT: Is there some way to specify the timezone when creating deadline
? I think this is a possible solution.