Search code examples
fluttertimezoneutc

How to display UTC time in local time


In my flutter application I get appointment time in UTC format from a server. I would like to display it in local time.

Is there a way to convert UTC to local time in flutter?


Solution

  • Dart has inbuilt DateTime type that provides quite a few handy methods to convert between time formats.

    void main() {
      var utc = DateTime.parse("2020-06-11 17:47:35 Z");
      print(utc.toString());             // 2020-06-11 17:47:35.000Z
      print(utc.isUtc.toString());       // true
      print(utc.toLocal().toString());   //2020-06-11 23:17:35.000
    }