How to get timezone name in Flutter?

Viewed 2676

How to fetch current timezone name Asia/Calcutta in Flutter/Dart?

DateTime.now().timeZoneName fetches String IST.
DateTime.now().timeZoneOffset fetches Duration 5:30:00.000000.

Intl.DateTimeFormat().resolvedOptions().timeZone gives the desired result, Asia/Calcutta, in JavaScript.

Any help is appreciated. Thanks.

2 Answers

I got the timezone fixed in Flutter this way.

import 'package:timezone/data/latest.dart' as tz;
import 'package:timezone/timezone.dart' as tz;
static const platform = const MethodChannel('channel NAME');
Future<void> _configureLocalTimeZone() async {
    tz.initializeTimeZones();
    var locations = tz.timeZoneDatabase.locations;
    final locationName = tz.getLocation(locations.keys.first); //Asia/Calcutta
    tz.setLocalLocation(locationName);
  }

Calling

await _configureLocalTimeZone();
Related