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.

Share:
2,979
Mohammed Sadakath Ali Aamiri
Author by

Mohammed Sadakath Ali Aamiri

Updated on December 20, 2022

Comments

  • Mohammed Sadakath Ali Aamiri
    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
      JideGuru almost 4 years
      That 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
    Mohammed Sadakath Ali Aamiri almost 4 years
    yes, but how do I get in format GMT +5.5hrs instead of 05:30:00 hours
  • Hemal Moradiya
    Hemal Moradiya almost 3 years
    Have you find any possible solution for this @MohammedSadakathAliAamiri
  • Admin
    Admin about 2 years
    Your 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.