my_timezone 0.0.4 copy "my_timezone: ^0.0.4" to clipboard
my_timezone: ^0.0.4 copied to clipboard

A Flutter plugin for reading local and available IANA time zone identifiers on Android, iOS, macOS, and web.

codecov GitHub Buy Me A Coffee PayPal Sponsor Support Me on Ko-fi

my_timezone returns the device's local IANA time zone identifier and the available identifiers on Android, iOS, macOS, and web.

Features #

  • Get the local timezone from the native layer.
  • Get the list of available timezones.
  • Uses one stable MethodChannel contract across Android, iOS, macOS, and web.
  • Requires Flutter 3.47.1 or newer and Dart 3.13.1 or newer.

Platform requirements #

  • Android API 24 or newer.
  • iOS 15.0 or newer.
  • macOS 12.0 or newer.
  • A modern browser with Intl.DateTimeFormat support.

Installation #

Add the following to your pubspec.yaml:

my_timezone: ^0.0.4

Then run:

flutter pub get

Basic usage #

import 'package:my_timezone/my_timezone.dart';

final String localTimezone = await MyTimezone.getLocalTimezone();
final List<String> availableTimezones =
    await MyTimezone.getAvailableTimezones();

On web, browsers expose the local identifier but not the complete IANA time zone database. getAvailableTimezones() therefore returns a one-item list containing the local identifier.

Example in a widget #

class _MyAppState extends State<MyApp> {
  String? _timezone;

  @override
  void initState() {
    super.initState();
    _loadTimezone();
  }

  Future<void> _loadTimezone() async {
    final timezone = await MyTimezone.getLocalTimezone();
    if (!mounted) return;
    setState(() => _timezone = timezone);
  }
}

Contribution #

If you have any suggestions or find any issues, feel free to open an issue or submit a pull request on GitHub.

Developer Team: #

Any comments please contact us ThaoDoan and DucNguyen.

2
likes
160
points
55
downloads
screenshot

Documentation

API reference

Publisher

verified publisherwongcoupon.com

Weekly Downloads

A Flutter plugin for reading local and available IANA time zone identifiers on Android, iOS, macOS, and web.

Repository (GitHub)
View/report issues

Topics

#timezone #local-time #device-info #flutter-plugin #cross-platform

Funding

Consider supporting this project:

buymeacoffee.com
ko-fi.com
github.com
paypal.me

License

MIT (license)

Dependencies

flutter, flutter_web_plugins

More

Packages that depend on my_timezone

Packages that implement my_timezone