Dart DateTime.utc()
Syntax & Examples
Syntax of DateTime.utc
The syntax of DateTime.DateTime.utc constructor is:
DateTime.utc(int year, [int month = 1, int day = 1, int hour = 0, int minute = 0, int second = 0, int millisecond = 0, int microsecond = 0])
This DateTime.utc constructor of DateTime constructs a DateTime
instance specified in the UTC time zone.
Parameters
Parameter | Optional/Required | Description |
---|---|---|
year | required | the year |
month | optional [default value is 1] | the month (1 - 12) |
day | optional [default value is 1] | the day of the month (1 - 31) |
hour | optional [default value is 0] | the hour of the day (0 - 23) |
minute | optional [default value is 0] | the minute of the hour (0 - 59) |
second | optional [default value is 0] | the second of the minute (0 - 59) |
millisecond | optional [default value is 0] | the millisecond of the second (0 - 999) |
microsecond | optional [default value is 0] | the microsecond of the millisecond (0 - 999) |
✐ Examples
1 Create a DateTime object for 10:30 AM, May 3, 2024, UTC time zone
In this example,
- We use the
DateTime.utc()
constructor to create a DateTime object representing 10:30 AM, May 3, 2024, in the UTC time zone. - We print the DateTime object to standard output.
Dart Program
void main() {
var dateTime = DateTime.utc(2024, 5, 3, 10, 30, 0);
print(dateTime);
}
Output
2024-05-03 10:30:00.000Z
2 Create a DateTime object for 10:30 AM, May 3, 2024, UTC time zone
In this example,
- We use the
DateTime.utc()
constructor to create a DateTime object representing 10:30 AM, May 3, 2024, in the UTC time zone. - We print the DateTime object to standard output.
Dart Program
void main() {
var dateTime = DateTime.utc(2024, 5, 3, 10, 30, 0);
print(dateTime);
}
Output
2024-05-03 10:30:00.000Z
3 Create a DateTime object for 10:30 AM, May 3, 2024, UTC time zone
In this example,
- We use the
DateTime.utc()
constructor to create a DateTime object representing 10:30 AM, May 3, 2024, in the UTC time zone. - We print the DateTime object to standard output.
Dart Program
void main() {
var dateTime = DateTime.utc(2024, 5, 3, 10, 30, 0);
print(dateTime);
}
Output
2024-05-03 10:30:00.000Z
Summary
In this Dart tutorial, we learned about DateTime.utc constructor of DateTime: the syntax and few working examples with output and detailed explanation for each example.