Dart DateTime minute
Syntax & Examples


Syntax of DateTime.minute

The syntax of DateTime.minute property is:

 int minute 

This minute property of DateTime the minute [0...59].

Return Type

DateTime.minute returns value of type int.



✐ Examples

1 Get current minute

In this example,

  1. We create a DateTime object now with the current date and time using DateTime.now().
  2. We access the minute property of now to get the current minute value.
  3. We print the current minute value to standard output.

Dart Program

void main() {
  DateTime now = DateTime.now();
  int currentMinute = now.minute;
  print('Current minute: $currentMinute');
}

Output

Current minute: 46
(Output may change based on the current time.)

2 Get minute value from a specific date and time

In this example,

  1. We create a DateTime object date representing a specific date and time (2024-05-03 15:30 in this example).
  2. We access the minute property of date to get the minute value for that date and time.
  3. We print the minute value to standard output.

Dart Program

void main() {
  DateTime date = DateTime(2024, 5, 3, 15, 30);
  int minuteValue = date.minute;
  print('Minute value: $minuteValue');
}

Output

Minute value: 30

3 Get minute value at midnight

In this example,

  1. We create a DateTime object midnight representing midnight on a specific date (2024-05-03 in this example).
  2. We access the minute property of midnight to get the minute value at midnight for that date.
  3. We print the midnight minute value to standard output.

Dart Program

void main() {
  DateTime midnight = DateTime(2024, 5, 3, 0, 0);
  int midnightMinute = midnight.minute;
  print('Midnight minute: $midnightMinute');
}

Output

Midnight minute: 0

Summary

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