DEV Community


Posted on

using Timezone package in flutter

Timezone package makes life a bit easier to deal with those pain in the neck issues related to timezone. However, I had a bunch of issues using that package, so documenting them here for someone else to save some time.

git clone
cd timezone
flutter pub get
flutter pub run tool/get -s 2020a
cd lib/data
  • Add it to your codebase.
cp lib/data/2020a* <project_dir>/assets/timezone/
cd <project_dir>
git add->commit->push

Also, add it to your pubspec file under assets with the path you used above.

  • Use it in your code.
  Future<void> initTimezones() async {
    // get device timezone
    String dtz = await FlutterNativeTimezone.getLocalTimezone();

    // Load timezone data
    var byteData = await rootBundle.load('assets/timezone/2020a.tzf');
    // set the local location.

    // Iterate and use through the list of timezones.
    _locations = tz.timeZoneDatabase.locations;
    _locations.values.forEach((element) {
  • For timezone conversion, readme on the package provides great examples, so I will skip repetition.

Hope this helps someone.

Discussion (1)

aesthytik profile image
Vipin Kumar Rawat

Hey Shailesh, i have been trying to implemet timezone specific time in the app,
Setup is done now,

I want to know how to add a default timezone for whole app.
I dont want to everytime convert the time.

Is there any way so that i set the time to specific timezone by default?
ad when i do it gives only that time?