# What is the current time around the world? Utilizing std::chrono with time zones in C++23

DevFeed: [What is the current time around the world? Utilizing std::chrono with time zones in C++23](<https://devfeed.tech/articles/what-is-the-current-time-around-the-world-utilizing-std-chrono-with-time-zones-in-c-23-53302.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2024/chrono_dates_zones/>)

Published: 2024-11-03T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [DateTime](<https://devfeed.tech/topics/datetime.md>), [Code](<https://devfeed.tech/topics/code.md>), [gcc](<https://devfeed.tech/topics/gcc.md>)

Tags: [c-plus-plus-23](<https://devfeed.tech/tags/c-plus-plus-23.md>), [clock](<https://devfeed.tech/tags/clock.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [formatting](<https://devfeed.tech/tags/formatting.md>), [time](<https://devfeed.tech/tags/time.md>), [utc](<https://devfeed.tech/tags/utc.md>)

## AI overview

This tutorial demonstrates how to use C++20 and C++23 date and time facilities with std::chrono. It covers formatting dates and times, retrieving times in different time zones, handling daylight saving time, and using the IANA time-zone database through operating-system support.

## Source excerpt

In this blog post, we will explore handling dates using std::chrono, including time zones. We'll utilize the latest features of the library to retrieve the current time across various time zones, taking into account daylight saving time changes as well. Additionally, we will incorporate new capabilities introduced in C++23, such as enhanced printing functions and more. Let's start with the following code that prints the current date and time: #include <chrono> #include <print> int main() { auto now = std::chrono::system_clock::now(); std::print("now is {}", now); } You can run it through Compiler Explorer In my session, I'm getting the following results: Now is 2024-11-01 11:44:06.374573703 It's simple, but what time zone are we in? Can we print it in a shorter form? How can we check the time around the world? What about daylight saving time? First things first: time output. Improving the print As you can see, I used std::print from C++23, which is available in GCC 14! By default, the time point obtained from ::now() is printed with full information, but we can change it and adjust it. For example: Basic Date and Time Formatting Show just the date: {0:%F} will format the date as YYYY-MM-DD. Show time in hh:mm:ss format: {0:%T} will format the time as HH:MM:SS. Show the name of the month and/or day of the week: {0:%A, %B} will format it as Day, Month. Advanced Formatting Options Year and Month: {0:%Y}: Full year (e.g., 2024). {0:%y}: Last two digits of the year (e.g., 24). {0:%B}: Full month name (e.g., November). {0:%b}: Abbreviated month name (e.g., Nov). Day and Week: {0:%d}: Day of the month, zero-padded (e.g., 01). {0:%A}: Full weekday name (e.g., Friday). {0:%a}: Abbreviated weekday name (e.g., Fri). Time of Day: {0:%H}: Hour (24-hour clock), zero-padded (e.g., 14). {0:%I}: Hour (12-hour clock), zero-padded (e.g., 02). {0:%M}: Minute, zero-padded (e.g., 05). {0:%S}: Second, zero-padded (e.g., 09). {0:%p}: AM/PM designation. Time Zone: {0:%Z}: Time zone abbrevia