Dart Duration inMicroseconds
Syntax & Examples


Duration.inMicroseconds property

The `inMicroseconds` property in Dart returns the number of whole microseconds spanned by this Duration.


Syntax of Duration.inMicroseconds

The syntax of Duration.inMicroseconds property is:

 int inMicroseconds 

This inMicroseconds property of Duration returns number of whole microseconds spanned by this Duration.

Return Type

Duration.inMicroseconds returns value of type int.



✐ Examples

1 Duration with seconds and microseconds

In this example,

  1. We create a Duration object duration with 2 seconds and 500 microseconds.
  2. We use the inMicroseconds property to get the number of microseconds as an integer.
  3. We then print the result to standard output.

Dart Program

void main() {
  Duration duration = Duration(seconds: 2, microseconds: 500);
  int microseconds = duration.inMicroseconds;
  print('Number of microseconds: $microseconds');
}

Output

Number of microseconds: 2000500

2 Duration with minutes and milliseconds

In this example,

  1. We create a Duration object duration with 1 minute and 500 milliseconds.
  2. We use the inMicroseconds property to get the number of microseconds as an integer.
  3. We then print the result to standard output.

Dart Program

void main() {
  Duration duration = Duration(minutes: 1, milliseconds: 500);
  int microseconds = duration.inMicroseconds;
  print('Number of microseconds: $microseconds');
}

Output

Number of microseconds: 60500000

3 Duration with hours and minutes

In this example,

  1. We create a Duration object duration with 3 hours and 20 minutes.
  2. We use the inMicroseconds property to get the number of microseconds as an integer.
  3. We then print the result to standard output.

Dart Program

void main() {
  Duration duration = Duration(hours: 3, minutes: 20);
  int microseconds = duration.inMicroseconds;
  print('Number of microseconds: $microseconds');
}

Output

Number of microseconds: 12000000000

Summary

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