Skip to content

Commit a3e8f36

Browse files
committed
Add doc example for how to determine total number of secs in Duration.
1 parent bdd8e7f commit a3e8f36

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/libstd/time/duration.rs

+15
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,21 @@ impl Duration {
128128
/// let duration = Duration::new(5, 730023852);
129129
/// assert_eq!(duration.as_secs(), 5);
130130
/// ```
131+
///
132+
/// To determine the total number of seconds represented by the `Duration`,
133+
/// use `as_secs` in combination with [`subsec_nanos`]:
134+
///
135+
/// ```
136+
/// use std::time::Duration;
137+
///
138+
/// let duration = Duration::new(5, 730023852);
139+
///
140+
/// assert_eq!(5.730023852,
141+
/// duration.as_secs() as f64
142+
/// + duration.subsec_nanos() as f64 * 1e-9);
143+
/// ```
144+
///
145+
/// [`subsec_nanos`]: #method.subsec_nanos
131146
#[stable(feature = "duration", since = "1.3.0")]
132147
#[inline]
133148
pub fn as_secs(&self) -> u64 { self.secs }

0 commit comments

Comments
 (0)