Skip to content

Commit b2514bf

Browse files
authored
add Duration::as_millis
1 parent 13fd5e9 commit b2514bf

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/libstd/time/duration.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,23 @@ impl Duration {
126126
#[inline]
127127
pub fn as_secs(&self) -> u64 { self.secs }
128128

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+
129146
/// Returns the nanosecond precision represented by this `Duration`.
130147
///
131148
/// This method does **not** return the length of the duration when

0 commit comments

Comments
 (0)