File tree 1 file changed +17
-0
lines changed
1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -126,6 +126,23 @@ impl Duration {
126
126
#[ inline]
127
127
pub fn as_secs ( & self ) -> u64 { self . secs }
128
128
129
+ /// Returns the number of whole milliseconds represented by this `Duration`.
130
+ ///
131
+ /// The extra precision represented by this duration is ignored (i.e. extra
132
+ /// nanoseconds are not represented in the returned value).
133
+ ///
134
+ /// # Examples
135
+ ///
136
+ /// ```
137
+ /// use std::time::Duration;
138
+ ///
139
+ /// let half_second = Duration::from_millis(500);
140
+ /// assert_eq!(half_second.as_millis(), 500);
141
+ /// ```
142
+ #[ unstable( feature = "duration_as_millis" , issue = "0" ) ]
143
+ #[ inline]
144
+ pub fn as_millis ( & self ) -> u64 { self . secs * 1000 + self . nanos as u64 / 1_000_000 }
145
+
129
146
/// Returns the nanosecond precision represented by this `Duration`.
130
147
///
131
148
/// This method does **not** return the length of the duration when
You can’t perform that action at this time.
0 commit comments