srawlins / timezone

Time zone database and time zone aware DateTime object for Dart.
BSD 2-Clause "Simplified" License
102 stars 54 forks source link

tz.TZDateTime.now() Gives device time instead of the Timezone's time #98

Open shabeenabarde opened 3 years ago

shabeenabarde commented 3 years ago

**So I am trying to get Africa/Nairobi's time because my app needs a country's exact time to work, and if the user's device is 2 minutes infront or behind, it won't work. I personally needs the exact time for my API's timestamp.

So I tried to use this package but it still prints out the device time instead of the timezone's time. Why is that?

Below are the functions that I am using :**

Future<List> loadDefaultData() async { var byteData = await rootBundle.load('packages/timezone/data/2020a.tzf'); return byteData.buffer.asUint8List(); }

timezonetesting() { loadDefaultData().then((rawData) { initializeDatabase(rawData); var africa = getLocation('Africa/Nairobi'); // var now = tz.TZDateTime.now(africa); var now = tz.TZDateTime.now(africa); // var now1 = tz.TZDateTime.local(); // var now = tz.TZDateTime.now(africa);

  print("africa is $africa && now is $now");
});

}

khaledaboellil commented 1 year ago

How did u fix it ?