i am currently working on a world clock app using flutter, can any one recommend dependencies or API i can integrate into my app that provide a list of places around the world, another issue i am having is getting the app to display current date and time of those selected places
Asked
Active
Viewed 1,484 times
1
-
Please provide enough code so others can better understand or reproduce the problem. – Community Apr 26 '22 at 11:41
1 Answers
2
The DateTime
class of Dart supports UTC and the local time zone. If you want to calculate a timestamp to a different time zone, check out the timezone
package on pub.dev.
https://pub.dev/packages/timezone
It supports something like this for example:
import 'package:timezone/standalone.dart' as tz;
Future<void> setup() async {
await tz.initializeTimeZone();
var detroit = tz.getLocation('America/Detroit');
var now = tz.TZDateTime.now(detroit);
}
It also consists of a time zone database:
import 'package:timezone/timezone.dart' as tz;
import 'package:timezone/data/latest.dart' as tz;
void main() {
tz.initializeTimeZones();
var locations = tz.timeZoneDatabase.locations;
print(locations.length); // => 429
print(locations.keys.first); // => "Africa/Abidjan"
print(locations.keys.last); // => "US/Pacific"
}

Tim Brückner
- 1,928
- 2
- 16
- 27