我有以下Javascript代码来获取小时并显示它是否是早晨,晚上等。但是getHours()总是给我一个错误的值。如果我在浏览器中使用它的正确但反应原生它总是一个错误的值。这段代码中的任何错误?
let date = new Date();
let day = date.getDate();
let month = allMonths[date.getMonth()];
let year = date.getFullYear();
let hour = date.getHours();
let minute = date.getMinutes();
let greeting = '';
if(day < 10){
day = '0'+day;
}
if(hour < 12 ){
greeting = 'Morning!';
}else if(hour < 13 && hour >= 12){
greeting = 'Afternoon!';
}else if(hour < 18 && hour >= 13){
greeting = 'Evening!';
}else {
greeting = 'Night!';
}