How to get GMT timeoffset value for current time in Dart/Flutter
2,979
The timeZoneOffset
gives you the difference between the timezone of your device and UTC.
Since UTC
is the same time with GMT
then timeZoneOffset
give you the +/- GMT offset
you need.
In your Question, you said the offset for India is +5.30
and when you printed print(timezoneOffset)
it gave you 05:30:00
which is exactly the 5:30
offset you needed.
Author by
Mohammed Sadakath Ali Aamiri
Updated on December 20, 2022Comments
-
Mohammed Sadakath Ali Aamiri over 1 year
I'm developing an application where I need to get only GMT offset time, i.e. for India +5.30. How do I achieve this dart.
var now = new DateTime.now(); var timezoneOffset=now.timeZoneOffset;
print (timezoneOffset); console : 05:30:00
how to get +/- GMT offset?
-
JideGuru almost 4 yearsThat is the offset giving to you. You said the offset for india is +5:50 and the console printed out
05:30:00
which is exactly what you need
-
-
Mohammed Sadakath Ali Aamiri almost 4 yearsyes, but how do I get in format GMT +5.5hrs instead of 05:30:00 hours
-
Hemal Moradiya almost 3 yearsHave you find any possible solution for this @MohammedSadakathAliAamiri
-
Admin about 2 yearsYour answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.