I have created below program in which I tried to compare date and time. but it is giving different answers in different compilers.
In tutorials point compiler it is working as expected : tutorialspoint
But, In repl.it compiler it is giving me wrong output : repl.it
Why this problem is happening?
let todayDate = () => {
var today = new Date();
var dateAndTime = today.toLocaleString('en-GB', { timeZone: 'Asia/Kolkata' })
var fulldate = dateAndTime.split(",")[0].split("/")
var dd = fulldate[0]
var mm = fulldate[1]
var yyyy = fulldate[2]
return yyyy + '/' + mm + '/' + dd;
}
let currentTime = () => {
var today = new Date();
var dateAndTime = today.toLocaleString('en-GB', { timeZone: 'Asia/Kolkata' })
var time = dateAndTime.split(",")[1].split(":")
var hh = time[0].replace(/^\s+|\s+$/gm,'');
var mm = time[1]
var ss = time[2]
return Date.parse(`${todayDate()} ${hh}:${mm}:${ss}`);
}
if (currentTime() > Date.parse(`${todayDate()} 18:00:00`) && currentTime() < Date.parse(`${todayDate()} 22:52:58`)){
console.log('Welcome')
}
else{
console.log('Comeback Later')
}
console.log(currentTime())
console.log(todayDate())