扑-DateTime.now()在我的当地时间不一样 [英] flutter - DateTime.now() not same in my local time

查看:57
本文介绍了扑-DateTime.now()在我的当地时间不一样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有个案例来检查商店的营业时间.我用下面的代码解决了这个问题:

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");
}

但是当我打印 DateTime.now()时,这个时间与当前时间不匹配吗?我已经尝试过使用当前时间手动输入,以确保代码检查营业时间和营业时间及其工作情况.

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.

推荐答案

好吧,这浪费了我很多时间,我回答它是为了帮助某人可能遇到相同的问题.修改模拟器设置后,它可以正常工作.

Well, this waste me lot of time, I answer it to help someone may encounter same problem. After modify emulator settings, it work OK.

这篇关于扑-DateTime.now()在我的当地时间不一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆