Complete Flutter Project Solutions
How to Get Current Timezone In Flutter?
Sometimes users need to show data that requires showing Date Picker in a Mobile Application. To display, the same kind of data Date Picker is used. In this article, we will go through how to get current Timezone in Flutter ??
How to Get Current Timezone In Flutter ??
There is a great library for this: https://pub.dev/packages/flutter_native_timezone
DateTime is the default class give use timezone and time offset both required to solve timezone related issue.
DateTime dateTime = DateTime.now(); print(dateTime.timeZoneName); print(dateTime.timeZoneOffset);
We will get output like the below:
1. India
timeZoneName: IST timeZoneOffset: 5:30:00.000000
2. America/Los_Angeles
timeZoneName: PST timeZoneOffset: -8:00:00.000000
You can also check the available timezone list:
class MyHomePage extends StatefulWidget { const MyHomePage({Key? key, required this.title}) : super(key: key); final String title; @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { @override Widget build(BuildContext context) { DateTime now = DateTime.now(); var timezone = now.timeZoneName; var offset = now.timeZoneOffset; return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( "TimeZone Name : $timezone", ), Text( "TimeZone Offset : $offset", ), ], ), ), ); } }
https://help.syncfusion.com/flutter/calendar/timezone
Output
Conclusion:
Thanks for Reading !!!
In this article, We have been through how to get the current Timezone in Flutter ??
Keep Learning !!! Keep Fluttering !!!
Flutter Agency is an online community dedicated to learning Flutter projects, development tips, issue resolution, news & industry updates. Consult our developer to turn your business idea into an amazing application that grows your business.
Request a Quote