时区颤动(作为ZoneId) [英] Flutter Timezone (as ZoneId)

查看:132
本文介绍了时区颤动(作为ZoneId)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Flutter相对较新.在进行实验时,遇到了一个问题.我的REST Api使用时区参数(区域ID格式,例如Europe/London).

I am relative new to Flutter. While I was experimenting, I came across with an issue. My REST Api takes a timezone parameter (Zone ID format such as Europe/London).

我看到了 https://pub.dartlang.org/packages/flutter_native_timezone https://pub.dartlang.org/packages/timezone ,但这些都不适合我需求.

I saw both https://pub.dartlang.org/packages/flutter_native_timezone and https://pub.dartlang.org/packages/timezone, but neither of those serve my needs.

我的目标是,当用户连接到互联网时(如果可能,不授予应用程序任何位置访问权限),请获取ZoneId格式的时区并提供我的后端信息,以制定必要的日期和时间调整.与此类似

My goal is, when the user connect to the internet (without giving any location access to the app, if it is possible), get the timezone in ZoneId format and feed my back end in order to make the necessary date and time adjustments. Something similar to this

>>> var timezone = jstz.determine();
>>> timezone.name(); 
"Europe/London"

https://bitbucket.org/pellepim/jstimezonedetect

任何见解都会非常有帮助.

Any insights will be really helpful.

预先感谢

推荐答案

我也一直在寻找这个,这就是我发现的内容: https://pub.dev/packages/flutter_native_timezone

I've been also looking for this and here's what I found: https://pub.dev/packages/flutter_native_timezone

它有点笨拙,但似乎可以在iOS和Android上正常工作.希望这会帮助有需要的人.

It a bit hacky under the hood, but it seems to work properly on both iOS and Android. Hope this will help someone in need.

用法:

final String currentTimeZone = await FlutterNativeTimezone.getLocalTimezone();
print(currentTimeZone); // Europe/Moscow

这篇关于时区颤动(作为ZoneId)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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