Dart Duration inMinutes
Syntax & Examples
Duration.inMinutes property
The `inMinutes` property in Dart returns the number of whole minutes spanned by this Duration.
Syntax of Duration.inMinutes
The syntax of Duration.inMinutes property is:
int inMinutes
This inMinutes property of Duration returns the number of whole minutes spanned by this Duration.
Return Type
Duration.inMinutes returns value of type int
.
✐ Examples
1 Duration with hours and minutes
In this example,
- We create a Duration object
duration
with 2 hours and 30 minutes. - We use the
inMinutes
property to get the number of minutes as an integer. - We then print the result to standard output.
Dart Program
void main() {
Duration duration = Duration(hours: 2, minutes: 30);
int minutes = duration.inMinutes;
print('Number of minutes: $minutes');
}
Output
Number of minutes: 150
2 Duration with days and hours
In this example,
- We create a Duration object
duration
with 1 day and 12 hours. - We use the
inMinutes
property to get the number of minutes as an integer. - We then print the result to standard output.
Dart Program
void main() {
Duration duration = Duration(days: 1, hours: 12);
int minutes = duration.inMinutes;
print('Number of minutes: $minutes');
}
Output
Number of minutes: 2160
3 Duration with seconds
In this example,
- We create a Duration object
duration
with 90 seconds. - We use the
inMinutes
property to get the number of minutes as an integer. - We then print the result to standard output.
Dart Program
void main() {
Duration duration = Duration(seconds: 90);
int minutes = duration.inMinutes;
print('Number of minutes: $minutes');
}
Output
Number of minutes: 1
Summary
In this Dart tutorial, we learned about inMinutes property of Duration: the syntax and few working examples with output and detailed explanation for each example.