# Converting a UTC Date-Time String to a UNIX Epoch Timestamp in C and C++

DevFeed: [Converting a UTC Date-Time String to a UNIX Epoch Timestamp in C and C++](<https://devfeed.tech/articles/the-surprising-struggle-to-get-a-unix-epoch-time-from-a-utc-string-in-c-or-c-36444.md>)

Original publisher: [Read original article](<https://berthub.eu/articles/posts/how-to-get-a-unix-epoch-from-a-utc-date-time-string/>)

Published: 2025-01-19T15:02:00Z

Content type: tutorial

Language: en

Sources: [Bert Hubert's writings](<https://devfeed.tech/sources/bert-hubert-s-writings.md>)

Topics: [C](<https://devfeed.tech/topics/c.md>), [POSIX](<https://devfeed.tech/topics/posix.md>), [C++](<https://devfeed.tech/topics/c-plus-plus.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [posix](<https://devfeed.tech/tags/posix.md>), [programming](<https://devfeed.tech/tags/programming.md>), [unix](<https://devfeed.tech/tags/unix.md>), [utc](<https://devfeed.tech/tags/utc.md>)

## AI overview

The article examines how to convert a UTC date-time string into a UNIX epoch timestamp in C and C++. It discusses unexpected behavior in POSIX time-handling functions and the complications caused by local times and daylight-saving transitions.

## Source excerpt

So how hard could it be. As input we have something like Fri, 17 Jan 2025 06:07:07 in UTC, and we'd like to turn this into 1737094027, the notional (but not actual) number of seconds that have passed since 1970-01-01 00:00:00 UTC. Trying to figure this out led me to discover many 'surprise features' and otherwise unexpected behaviour of POSIX time handling functions as implemented in various C libraries & the languages that build on them.