How to get GMT timeoffset value for current time in Dart/Flutter

Viewed 3420

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?

4 Answers

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.

You can use DateTime class.

DateTime.now().timeZoneOffset; // return Duration()

DateTime.now().timeZoneOffset.inHours; // return int

DateTime.now().timeZoneOffset.inMinutes; // return int
Its in dart/flutter hope you can convert
      var t=DateTime.now();
        t=t.add(const Duration(minutes: 1));
        print(t.timeZoneName);
        var add=t.hour.toString()+":"+t.minute.toString()+":"+t.second.toString();
    'send_after':'Sept ${t.day} ${t.year} ${add} ${t.timeZoneName}'
Related