cplusplus.com
Open in
urlscan Pro
54.39.7.252
Public Scan
Submitted URL: http://cplusplus.com/reference/chrono/duration/duration/
Effective URL: https://cplusplus.com/reference/chrono/duration/duration/
Submission: On October 23 via api from NL — Scanned from CA
Effective URL: https://cplusplus.com/reference/chrono/duration/duration/
Submission: On October 23 via api from NL — Scanned from CA
Form analysis
2 forms found in the DOM<form class="gsc-search-box gsc-search-box-tools" accept-charset="utf-8">
<table cellspacing="0" cellpadding="0" role="presentation" class="gsc-search-box">
<tbody>
<tr>
<td class="gsc-input">
<div class="gsc-input-box" id="gsc-iw-id1">
<table cellspacing="0" cellpadding="0" role="presentation" id="gs_id50" class="gstl_50 gsc-input" style="width: 100%; padding: 0px;">
<tbody>
<tr>
<td id="gs_tti50" class="gsib_a"><input autocomplete="off" type="text" size="10" class="gsc-input" name="search" title="search" aria-label="search" id="gsc-i-id1" dir="ltr" spellcheck="false"
style="width: 100%; padding: 0px; border: none; margin: 0px; height: auto; outline: none;"></td>
<td class="gsib_b">
<div class="gsst_b" id="gs_st50" dir="ltr"><a class="gsst_a" href="javascript:void(0)" title="Clear search box" role="button" style="display: none;"><span class="gscb_a" id="gs_cb50" aria-hidden="true">×</span></a></div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<td class="gsc-search-button"><button class="gsc-search-button gsc-search-button-v2"><svg width="13" height="13" viewBox="0 0 13 13">
<title>search</title>
<path
d="m4.8495 7.8226c0.82666 0 1.5262-0.29146 2.0985-0.87438 0.57232-0.58292 0.86378-1.2877 0.87438-2.1144 0.010599-0.82666-0.28086-1.5262-0.87438-2.0985-0.59352-0.57232-1.293-0.86378-2.0985-0.87438-0.8055-0.010599-1.5103 0.28086-2.1144 0.87438-0.60414 0.59352-0.8956 1.293-0.87438 2.0985 0.021197 0.8055 0.31266 1.5103 0.87438 2.1144 0.56172 0.60414 1.2665 0.8956 2.1144 0.87438zm4.4695 0.2115 3.681 3.6819-1.259 1.284-3.6817-3.7 0.0019784-0.69479-0.090043-0.098846c-0.87973 0.76087-1.92 1.1413-3.1207 1.1413-1.3553 0-2.5025-0.46363-3.4417-1.3909s-1.4088-2.0686-1.4088-3.4239c0-1.3553 0.4696-2.4966 1.4088-3.4239 0.9392-0.92727 2.0864-1.3969 3.4417-1.4088 1.3553-0.011889 2.4906 0.45771 3.406 1.4088 0.9154 0.95107 1.379 2.0924 1.3909 3.4239 0 1.2126-0.38043 2.2588-1.1413 3.1385l0.098834 0.090049z">
</path>
</svg></button></td>
<td class="gsc-clear-button">
<div class="gsc-clear-button" title="clear results"> </div>
</td>
</tr>
</tbody>
</table>
</form>
Name: I_loginform — POST /user/access.cgi
<form name="I_loginform" method="POST" action="/user/access.cgi" style="display: none;">
<div class="fields"><input type="hidden" name="w" value="login"><input type="hidden" name="y" value="1"><input type="hidden" name="to" value="https://cplusplus.com/reference/chrono/duration/duration/">user name: <input type="text" name="l" id="l"
class="txt" size="8" title="Type user name"><br>password: <input type="password" name="p" id="p" class="txt" size="8" title="Type password"><br><input type="checkbox" name="rememberme" value="1" class="chk" id="rememberme"><label
for="rememberme"></label><input type="submit" class="rbtn" value="sign in">
<div class="forgot"><a href="/user/access.cgi?w=lostpass">Forgot your password?</a></div>
</div>
</form>
Text Content
cplusplus.com * TUTORIALS * REFERENCE * ARTICLES * FORUM × search user name: password: Forgot your password? please wait try again cancel forgot your password? sign up log in [Legacy version] C++ * Tutorials * Reference * Articles * Forum REFERENCE * C LIBRARY: * <cassert> (assert.h) * <cctype> (ctype.h) * <cerrno> (errno.h) * C++11 <cfenv> (fenv.h) * <cfloat> (float.h) * C++11 <cinttypes> (inttypes.h) * <ciso646> (iso646.h) * <climits> (limits.h) * <clocale> (locale.h) * <cmath> (math.h) * <csetjmp> (setjmp.h) * <csignal> (signal.h) * <cstdarg> (stdarg.h) * C++11 <cstdbool> (stdbool.h) * <cstddef> (stddef.h) * C++11 <cstdint> (stdint.h) * <cstdio> (stdio.h) * <cstdlib> (stdlib.h) * <cstring> (string.h) * C++11 <ctgmath> (tgmath.h) * <ctime> (time.h) * C++11 <cuchar> (uchar.h) * <cwchar> (wchar.h) * <cwctype> (wctype.h) * CONTAINERS: * C++11 <array> * <deque> * C++11 <forward_list> * <list> * <map> * <queue> * <set> * <stack> * C++11 <unordered_map> * C++11 <unordered_set> * <vector> * INPUT/OUTPUT: * <fstream> * <iomanip> * <ios> * <iosfwd> * <iostream> * <istream> * <ostream> * <sstream> * <streambuf> * MULTI-THREADING: * C++11 <atomic> * C++11 <condition_variable> * C++11 <future> * C++11 <mutex> * C++11 <thread> * OTHER: * <algorithm> * <bitset> * C++11 <chrono> * C++11 <codecvt> * <complex> * <exception> * <functional> * C++11 <initializer_list> * <iterator> * <limits> * <locale> * <memory> * <new> * <numeric> * C++11 <random> * C++11 <ratio> * C++11 <regex> * <stdexcept> * <string> * C++11 <system_error> * C++11 <tuple> * C++11 <type_traits> * C++11 <typeindex> * <typeinfo> * <utility> * <valarray> * <algorithm> * <bitset> * <cassert> (assert.h) * <cctype> (ctype.h) * <cerrno> (errno.h) * <cfloat> (float.h) * <ciso646> (iso646.h) * <climits> (limits.h) * <clocale> (locale.h) * <cmath> (math.h) * <complex> * <csetjmp> (setjmp.h) * <csignal> (signal.h) * <cstdarg> (stdarg.h) * <cstddef> (stddef.h) * <cstdio> (stdio.h) * <cstdlib> (stdlib.h) * <cstring> (string.h) * <ctime> (time.h) * <cwchar> (wchar.h) * <cwctype> (wctype.h) * <deque> * <exception> * <fstream> * <functional> * <iomanip> * <ios> * <iosfwd> * <iostream> * <istream> * <iterator> * <limits> * <list> * <locale> * <map> * <memory> * <new> * <numeric> * <ostream> * <queue> * <set> * <sstream> * <stack> * <stdexcept> * <streambuf> * <string> * <typeinfo> * <utility> * <valarray> * <vector> * C++11 <array> * C++11 <atomic> * C++11 <cfenv> (fenv.h) * C++11 <chrono> * C++11 <cinttypes> (inttypes.h) * C++11 <codecvt> * C++11 <condition_variable> * C++11 <cstdbool> (stdbool.h) * C++11 <cstdint> (stdint.h) * C++11 <ctgmath> (tgmath.h) * C++11 <cuchar> (uchar.h) * C++11 <forward_list> * C++11 <future> * C++11 <initializer_list> * C++11 <mutex> * C++11 <random> * C++11 <ratio> * C++11 <regex> * C++11 <system_error> * C++11 <thread> * C++11 <tuple> * C++11 <type_traits> * C++11 <typeindex> * C++11 <unordered_map> * C++11 <unordered_set> <CHRONO> * CLASSES * C++11 common_type (duration) * C++11 common_type (time_point) * C++11 duration * C++11 duration_values * C++11 high_resolution_clock * C++11 steady_clock * C++11 system_clock * C++11 time_point * C++11 treat_as_floating_point * FUNCTIONS * C++11 duration_cast * C++11 time_point_cast * CLASS TYPEDEFS * C++11 hours * C++11 microseconds * C++11 milliseconds * C++11 minutes * C++11 nanoseconds * C++11 seconds * C++11 common_type (duration) * C++11 common_type (time_point) * C++11 duration * C++11 duration_cast * C++11 duration_values * C++11 high_resolution_clock * C++11 hours * C++11 microseconds * C++11 milliseconds * C++11 minutes * C++11 nanoseconds * C++11 seconds * C++11 steady_clock * C++11 system_clock * C++11 time_point * C++11 time_point_cast * C++11 treat_as_floating_point DURATION * C++11 duration::~duration * C++11 duration::duration * C++11 duration operators * MEMBER FUNCTIONS * C++11 duration::count * STATIC MEMBER FUNCTIONS * C++11 duration::max * C++11 duration::min * C++11 duration::zero * C++11 duration operators * C++11 duration::count * C++11 duration::duration * C++11 duration::max * C++11 duration::min * C++11 duration::zero * C++11 duration::~duration * Reference * <chrono> * duration * duration public member function <chrono> STD::CHRONO::DURATION::DURATION (1) duration() = default; (2) duration (const duration& dtn); (3) template<class Rep2, class Period2>constexpr duration (const duration<Rep2,Period2>& dtn); (4) template<class Rep2>constexpr explicit duration (const Rep2& n); Construct duration object Constructs a duration object: default constructor (1) Constructs an object, with a default-initialized count value. from duration object (2), (3) Initializes the object to a duration of dtn. from representation (4) Initializes the object to a duration whose count is n. The initialization constructors (3) and (4) are only called when the Rep2 type is not wider than the rep type used in the newly constructed duration object (and cannot cause implicit truncation errors). In this regard, if the treat_as_floating_point value for rep is true, Rep2 is never considered wider. In order to force a conversion between duration types no matter their precisions, even if this can cause a truncation, you can use duration_cast. PARAMETERS dtn Another duration object. duration<Rep2,Period2> is a type that cannot cause an implicit truncation error when converted. n The count value. Rep2 is an arithmetic type (or a class emulating an arithmetic type). EXAMPLE 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 // duration constructor #include <iostream> #include <ratio> #include <chrono> int main () { typedef std::chrono::duration<int> seconds_type; typedef std::chrono::duration<int,std::milli> milliseconds_type; typedef std::chrono::duration<int,std::ratio<60*60>> hours_type; hours_type h_oneday (24); // 24h seconds_type s_oneday (60*60*24); // 86400s milliseconds_type ms_oneday (s_oneday); // 86400000ms seconds_type s_onehour (60*60); // 3600s //hours_type h_onehour (s_onehour); // NOT VALID (type truncates), use: hours_type h_onehour (std::chrono::duration_cast<hours_type>(s_onehour)); milliseconds_type ms_onehour (s_onehour); // 3600000ms (ok, no type truncation) std::cout << ms_onehour.count() << "ms in 1h" << std::endl; return 0; } Edit & run on cpp.sh Output: 3600000ms in 1h SEE ALSO duration_castDuration cast (function template)duration::countGet count (public member function) Home page | Privacy policy © cplusplus.com, 2000-2023 - All rights reserved - v3.3.4s Spotted an error? contact us x