I have a case to check the store opening-closed hours. Im solve this using the code below:
final _openHours = 09;
final _openMinute = 00;
final _closeHours = 15;
final _closeMinute = 00;
var now = DateTime.now();
print(now);
var _open = new DateTime(now.year, now.month, now.day, _openHours, _openMinute, now.second);
var _close = new DateTime(now.year, now.month, now.day, _closeHours, _closeMinute, now.second);
now.isAfter(_open) && now.isBefore(_close) {
print("online");
} else {
print("offline");
}
but when I print DateTime.now()
, this time does not match the current time?
I have tried it using manually input currently time to make sure the code checks the opening and closing hours, and its works.
DateTime.now
should return an instant in time anchored in the local time zone of the host. Is it running on a server? – Sporeprint(DateTime.now().timeZoneName);
look correct to you? – Percuss