我有个情况要检查商店的营业时间。 我用下面的代码解决了这个问题:
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");
}
但是当我打印DateTime.now()
时,这次与当前时间不匹配吗?
我已经尝试使用当前时间手动输入时间来确保代码检查了营业时间和营业时间及其工作情况。