[time.zone.zonedtime]

# 30 Time library [[time]](./#time)

## 30.11 Time zones [[time.zone]](time.zone#zonedtime)

### 30.11.7 Class template zoned_time [time.zone.zonedtime]

#### [30.11.7.1](#overview) Overview [[time.zone.zonedtime.overview]](time.zone.zonedtime.overview)

namespace std::chrono {template<class Duration, class TimeZonePtr = const time_zone*>class zoned_time {public:using duration = common_type_t<Duration, seconds>; private: TimeZonePtr zone_; // *exposition only* sys_time<duration> tp_; // *exposition only*using traits = zoned_traits<TimeZonePtr>; // *exposition only*public: zoned_time();
 zoned_time(const zoned_time&) = default;
 zoned_time& operator=(const zoned_time&) = default;

 zoned_time(const sys_time<Duration>& st); explicit zoned_time(TimeZonePtr z); explicit zoned_time(string_view name); template<class Duration2> zoned_time(const zoned_time<Duration2, TimeZonePtr>& y);

 zoned_time(TimeZonePtr z, const sys_time<Duration>& st);
 zoned_time(string_view name, const sys_time<Duration>& st);

 zoned_time(TimeZonePtr z, const local_time<Duration>& tp);
 zoned_time(string_view name, const local_time<Duration>& tp);
 zoned_time(TimeZonePtr z, const local_time<Duration>& tp, choose c);
 zoned_time(string_view name, const local_time<Duration>& tp, choose c); template<class Duration2, class TimeZonePtr2> zoned_time(TimeZonePtr z, const zoned_time<Duration2, TimeZonePtr2>& y); template<class Duration2, class TimeZonePtr2> zoned_time(TimeZonePtr z, const zoned_time<Duration2, TimeZonePtr2>& y, choose); template<class Duration2, class TimeZonePtr2> zoned_time(string_view name, const zoned_time<Duration2, TimeZonePtr2>& y); template<class Duration2, class TimeZonePtr2> zoned_time(string_view name, const zoned_time<Duration2, TimeZonePtr2>& y, choose c);

 zoned_time& operator=(const sys_time<Duration>& st);
 zoned_time& operator=(const local_time<Duration>& lt); operator sys_time<duration>() const; explicit operator local_time<duration>() const;

 TimeZonePtr get_time_zone() const;
 local_time<duration> get_local_time() const;
 sys_time<duration> get_sys_time() const;
 sys_info get_info() const; };

 zoned_time() -> zoned_time<seconds>; template<class Duration> zoned_time(sys_time<Duration>)-> zoned_time<common_type_t<Duration, seconds>>; template<class TimeZonePtrOrName>using *time-zone-representation* = // *exposition only* conditional_t<is_convertible_v<TimeZonePtrOrName, string_view>, const time_zone*,
 remove_cvref_t<TimeZonePtrOrName>>; template<class TimeZonePtrOrName> zoned_time(TimeZonePtrOrName&&)-> zoned_time<seconds, *time-zone-representation*<TimeZonePtrOrName>>; template<class TimeZonePtrOrName, class Duration> zoned_time(TimeZonePtrOrName&&, sys_time<Duration>)-> zoned_time<common_type_t<Duration, seconds>, *time-zone-representation*<TimeZonePtrOrName>>; template<class TimeZonePtrOrName, class Duration> zoned_time(TimeZonePtrOrName&&, local_time<Duration>,
 choose = choose::earliest)-> zoned_time<common_type_t<Duration, seconds>, *time-zone-representation*<TimeZonePtrOrName>>; template<class Duration, class TimeZonePtrOrName, class TimeZonePtr2> zoned_time(TimeZonePtrOrName&&, zoned_time<Duration, TimeZonePtr2>,
 choose = choose::earliest)-> zoned_time<common_type_t<Duration, seconds>, *time-zone-representation*<TimeZonePtrOrName>>;}

[1](#overview-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9701)

zoned_time represents a logical pairing of
a time_zone and a time_point with precision Duration[.](#overview-1.sentence-1)

zoned_time<Duration> maintains the invariant that
it always refers to a valid time zone and
represents a point in time that exists and is not ambiguous
in that time zone[.](#overview-1.sentence-2)

[2](#overview-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9709)

If Duration is not a specialization of chrono​::​duration,
the program is ill-formed[.](#overview-2.sentence-1)

[3](#overview-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9713)

Every constructor of zoned_time that
accepts a string_view as its first parameter
does not participate in
class template argument deduction ([[over.match.class.deduct]](over.match.class.deduct "12.2.2.9 Class template argument deduction"))[.](#overview-3.sentence-1)

#### [30.11.7.2](#ctor) Constructors [[time.zone.zonedtime.ctor]](time.zone.zonedtime.ctor)

[ð](#lib:zoned_time,constructor)

`zoned_time();
`

[1](#ctor-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9727)

*Constraints*: traits​::​default_zone() is a well-formed expression[.](#ctor-1.sentence-1)

[2](#ctor-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9731)

*Effects*: Initializes zone_ with traits​::​default_zone() and
default constructs tp_[.](#ctor-2.sentence-1)

[ð](#ctor-itemdecl:2)

`zoned_time(const sys_time<Duration>& st);
`

[3](#ctor-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9742)

*Constraints*: traits​::​default_zone() is a well-formed expression[.](#ctor-3.sentence-1)

[4](#ctor-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9746)

*Effects*: Initializes zone_ with traits​::​default_zone() and tp_ with st[.](#ctor-4.sentence-1)

[ð](#ctor-itemdecl:3)

`explicit zoned_time(TimeZonePtr z);
`

[5](#ctor-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9756)

*Preconditions*: z refers to a time zone[.](#ctor-5.sentence-1)

[6](#ctor-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9760)

*Effects*: Initializes zone_ with std​::​move(z) and
default constructs tp_[.](#ctor-6.sentence-1)

[ð](#ctor-itemdecl:4)

`explicit zoned_time(string_view name);
`

[7](#ctor-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9771)

*Constraints*: traits​::​locate_zone(string_view{}) is a well-formed expression andzoned_time is constructible from the return type of traits​::​locate_zone(string_view{})[.](#ctor-7.sentence-1)

[8](#ctor-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9776)

*Effects*: Initializes zone_ with traits​::​locate_zone(name) and
default constructs tp_[.](#ctor-8.sentence-1)

[ð](#ctor-itemdecl:5)

`template<class Duration2>
  zoned_time(const zoned_time<Duration2, TimeZonePtr>& y);
`

[9](#ctor-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9788)

*Constraints*: is_convertible_v<sys_time<Duration2>, sys_time<Duration>> is true[.](#ctor-9.sentence-1)

[10](#ctor-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9792)

*Effects*: Initializes zone_ with y.zone_ and tp_ with y.tp_[.](#ctor-10.sentence-1)

[ð](#ctor-itemdecl:6)

`zoned_time(TimeZonePtr z, const sys_time<Duration>& st);
`

[11](#ctor-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9802)

*Preconditions*: z refers to a time zone[.](#ctor-11.sentence-1)

[12](#ctor-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9806)

*Effects*: Initializes zone_ with std​::​move(z) and tp_ with st[.](#ctor-12.sentence-1)

[ð](#ctor-itemdecl:7)

`zoned_time(string_view name, const sys_time<Duration>& st);
`

[13](#ctor-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9816)

*Constraints*: zoned_time is constructible from the return type of traits​::​locate_zone(name) and st[.](#ctor-13.sentence-1)

[14](#ctor-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9820)

*Effects*: Equivalent to construction with {traits​::​locate_zone(name), st}[.](#ctor-14.sentence-1)

[ð](#ctor-itemdecl:8)

`zoned_time(TimeZonePtr z, const local_time<Duration>& tp);
`

[15](#ctor-15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9830)

*Constraints*: is_convertible_v<decltype(declval<TimeZonePtr&>()->to_sys(local_time<Duration>{})),
 sys_time<duration>> is true[.](#ctor-15.sentence-1)

[16](#ctor-16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9839)

*Preconditions*: z refers to a time zone[.](#ctor-16.sentence-1)

[17](#ctor-17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9843)

*Effects*: Initializes zone_ with std​::​move(z) and tp_ with zone_->to_sys(tp)[.](#ctor-17.sentence-1)

[ð](#ctor-itemdecl:9)

`zoned_time(string_view name, const local_time<Duration>& tp);
`

[18](#ctor-18)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9853)

*Constraints*: zoned_time is constructible from the return type of traits​::​locate_zone(name) and tp[.](#ctor-18.sentence-1)

[19](#ctor-19)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9857)

*Effects*: Equivalent to construction with {traits​::​locate_zone(name), tp}[.](#ctor-19.sentence-1)

[ð](#ctor-itemdecl:10)

`zoned_time(TimeZonePtr z, const local_time<Duration>& tp, choose c);
`

[20](#ctor-20)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9867)

*Constraints*: is_convertible_v<decltype(declval<TimeZonePtr&>()->to_sys(local_time<Duration>{}, choose::earliest)),
 sys_time<duration>> is true[.](#ctor-20.sentence-1)

[21](#ctor-21)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9876)

*Preconditions*: z refers to a time zone[.](#ctor-21.sentence-1)

[22](#ctor-22)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9880)

*Effects*: Initializes zone_ with std​::​move(z) and tp_ with zone_->to_sys(tp, c)[.](#ctor-22.sentence-1)

[ð](#ctor-itemdecl:11)

`zoned_time(string_view name, const local_time<Duration>& tp, choose c);
`

[23](#ctor-23)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9890)

*Constraints*: zoned_time is constructible from
the return type of traits​::​locate_zone(name), local_time<Duration>, and choose[.](#ctor-23.sentence-1)

[24](#ctor-24)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9895)

*Effects*: Equivalent to construction with {traits​::​locate_zone(name), tp, c}[.](#ctor-24.sentence-1)

[ð](#ctor-itemdecl:12)

`template<class Duration2, class TimeZonePtr2>
  zoned_time(TimeZonePtr z, const zoned_time<Duration2, TimeZonePtr2>& y);
`

[25](#ctor-25)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9906)

*Constraints*: is_convertible_v<sys_time<Duration2>, sys_time<Duration>> is true[.](#ctor-25.sentence-1)

[26](#ctor-26)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9910)

*Preconditions*: z refers to a valid time zone[.](#ctor-26.sentence-1)

[27](#ctor-27)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9914)

*Effects*: Initializes zone_ with std​::​move(z) and tp_ with y.tp_[.](#ctor-27.sentence-1)

[ð](#ctor-itemdecl:13)

`template<class Duration2, class TimeZonePtr2>
  zoned_time(TimeZonePtr z, const zoned_time<Duration2, TimeZonePtr2>& y, choose);
`

[28](#ctor-28)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9925)

*Constraints*: is_convertible_v<sys_time<Duration2>, sys_time<Duration>> is true[.](#ctor-28.sentence-1)

[29](#ctor-29)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9929)

*Preconditions*: z refers to a valid time zone[.](#ctor-29.sentence-1)

[30](#ctor-30)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9933)

*Effects*: Equivalent to construction with {z, y}[.](#ctor-30.sentence-1)

[31](#ctor-31)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9937)

[*Note [1](#ctor-note-1)*:

The choose parameter has no effect[.](#ctor-31.sentence-1)

â *end note*]

[ð](#ctor-itemdecl:14)

`template<class Duration2, class TimeZonePtr2>
  zoned_time(string_view name, const zoned_time<Duration2, TimeZonePtr2>& y);
`

[32](#ctor-32)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9949)

*Constraints*: zoned_time is constructible from
the return type of traits​::​locate_zone(name) and
the type zoned_time<Duration2, TimeZonePtr2>[.](#ctor-32.sentence-1)

[33](#ctor-33)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9955)

*Effects*: Equivalent to construction with {traits​::​locate_zone(name), y}[.](#ctor-33.sentence-1)

[ð](#ctor-itemdecl:15)

`template<class Duration2, class TimeZonePtr2>
  zoned_time(string_view name, const zoned_time<Duration2, TimeZonePtr2>& y, choose c);
`

[34](#ctor-34)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9966)

*Constraints*: zoned_time is constructible from
the return type of traits​::​locate_zone(name),
the type zoned_time<Duration2, TimeZonePtr2>, and
the type choose[.](#ctor-34.sentence-1)

[35](#ctor-35)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9973)

*Effects*: Equivalent to construction with {traits​::​locate_zone(name), y, c}[.](#ctor-35.sentence-1)

[36](#ctor-36)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9977)

[*Note [2](#ctor-note-2)*:

The choose parameter has no effect[.](#ctor-36.sentence-1)

â *end note*]

#### [30.11.7.3](#members) Member functions [[time.zone.zonedtime.members]](time.zone.zonedtime.members)

[ð](#lib:operator=,zoned_time)

`zoned_time& operator=(const sys_time<Duration>& st);
`

[1](#members-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9992)

*Effects*: After assignment, get_sys_time() == st[.](#members-1.sentence-1)

This assignment has no effect on the return value of get_time_zone()[.](#members-1.sentence-2)

[2](#members-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L9997)

*Returns*: *this[.](#members-2.sentence-1)

[ð](#lib:operator=,zoned_time_)

`zoned_time& operator=(const local_time<Duration>& lt);
`

[3](#members-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L10008)

*Effects*: After assignment, get_local_time() == lt[.](#members-3.sentence-1)

This assignment has no effect on the return value of get_time_zone()[.](#members-3.sentence-2)

[4](#members-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L10013)

*Returns*: *this[.](#members-4.sentence-1)

[ð](#lib:operator_sys_time,zoned_time)

`operator sys_time<duration>() const;
`

[5](#members-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L10024)

*Returns*: get_sys_time()[.](#members-5.sentence-1)

[ð](#lib:operator_local_time,zoned_time)

`explicit operator local_time<duration>() const;
`

[6](#members-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L10035)

*Returns*: get_local_time()[.](#members-6.sentence-1)

[ð](#lib:get_time_zone,zoned_time)

`TimeZonePtr get_time_zone() const;
`

[7](#members-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L10046)

*Returns*: zone_[.](#members-7.sentence-1)

[ð](#lib:get_local_time,zoned_time)

`local_time<duration> get_local_time() const;
`

[8](#members-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L10057)

*Returns*: zone_->to_local(tp_)[.](#members-8.sentence-1)

[ð](#lib:get_sys_time,zoned_time)

`sys_time<duration> get_sys_time() const;
`

[9](#members-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L10068)

*Returns*: tp_[.](#members-9.sentence-1)

[ð](#lib:get_info,zoned_time)

`sys_info get_info() const;
`

[10](#members-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L10079)

*Returns*: zone_->get_info(tp_)[.](#members-10.sentence-1)

#### [30.11.7.4](#nonmembers) Non-member functions [[time.zone.zonedtime.nonmembers]](time.zone.zonedtime.nonmembers)

[ð](#lib:operator==,zoned_time)

`template<class Duration1, class Duration2, class TimeZonePtr>
  bool operator==(const zoned_time<Duration1, TimeZonePtr>& x,
                  const zoned_time<Duration2, TimeZonePtr>& y);
`

[1](#nonmembers-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L10094)

*Returns*: x.zone_ == y.zone_ && x.tp_ == y.tp_[.](#nonmembers-1.sentence-1)

[ð](#lib:operator%3c%3c,zoned_time)

`template<class charT, class traits, class Duration, class TimeZonePtr>
  basic_ostream<charT, traits>&
    operator<<(basic_ostream<charT, traits>& os,
               const zoned_time<Duration, TimeZonePtr>& t);
`

[2](#nonmembers-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L10108)

*Effects*: Equivalent to:return os << format(os.getloc(), *STATICALLY-WIDEN*<charT>("{:L%F %T %Z}"), t);
