Dart DateTime isUtc
Syntax & Examples


Syntax of DateTime.isUtc

The syntax of DateTime.isUtc property is:

 bool isUtc 

This isUtc property of DateTime true if this DateTime is set to UTC time.

Return Type

DateTime.isUtc returns value of type bool.



✐ Examples

1 Check if the current DateTime is in UTC

In this example,

  1. We create a DateTime object dt using the DateTime.now() constructor, which represents the current date and time.
  2. We then access the isUtc property of dt to determine if it is set to UTC time.
  3. We print the result to standard output.

Dart Program

void main() {
  var dt = DateTime.now();
  print(dt.isUtc);
}

Output

Output varies depending on whether the current date and time is set to UTC.

2 Check if a specific DateTime is in UTC

In this example,

  1. We create a DateTime object dt using the DateTime.utc() constructor, specifying the year, month, and day.
  2. We then access the isUtc property of dt to determine if it is set to UTC time.
  3. We print the result to standard output.

Dart Program

void main() {
  var dt = DateTime.utc(2024, 5, 3);
  print(dt.isUtc);
}

Output

true

3 Check if a parsed DateTime is in UTC

In this example,

  1. We create a DateTime object dt by parsing a date-time string '2024-05-03T10:15:30' using the DateTime.parse() method.
  2. We then access the isUtc property of dt to determine if it is set to UTC time.
  3. We print the result to standard output.

Dart Program

void main() {
  var dt = DateTime.parse('2024-05-03T10:15:30');
  print(dt.isUtc);
}

Output

false

Summary

In this Dart tutorial, we learned about isUtc property of DateTime: the syntax and few working examples with output and detailed explanation for each example.