Dart Duration inSeconds
Syntax & Examples
Duration.inSeconds property
The `inSeconds` property in Dart returns the number of whole seconds spanned by a Duration object.
Syntax of Duration.inSeconds
The syntax of Duration.inSeconds property is:
int inSeconds
This inSeconds property of Duration returns the number of whole seconds spanned by this Duration.
Return Type
Duration.inSeconds returns value of type int
.
✐ Examples
1 Calculating seconds from days and hours
In this example,
- We create a Duration object
duration
with 2 days and 3 hours. - We get the total seconds using the
inSeconds
property. - We then print the total seconds to standard output.
Dart Program
void main() {
Duration duration = Duration(days: 2, hours: 3);
int seconds = duration.inSeconds;
print('Total seconds: $seconds');
}
Output
Total seconds: 183600
2 Calculating seconds from hours and minutes
In this example,
- We create a Duration object
duration
with 10 hours and 30 minutes. - We get the total seconds using the
inSeconds
property. - We then print the total seconds to standard output.
Dart Program
void main() {
Duration duration = Duration(hours: 10, minutes: 30);
int seconds = duration.inSeconds;
print('Total seconds: $seconds');
}
Output
Total seconds: 37800
3 Calculating seconds from minutes
In this example,
- We create a Duration object
duration
with 150 minutes. - We get the total seconds using the
inSeconds
property. - We then print the total seconds to standard output.
Dart Program
void main() {
Duration duration = Duration(minutes: 150);
int seconds = duration.inSeconds;
print('Total seconds: $seconds');
}
Output
Total seconds: 9000
Summary
In this Dart tutorial, we learned about inSeconds property of Duration: the syntax and few working examples with output and detailed explanation for each example.