Janaka
Janaka

Reputation: 2795

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?

Upvotes: 2

Views: 7158

Answers (1)

Joy Terence
Joy Terence

Reputation: 730

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
}

Upvotes: 7

Related Questions