Using this free, open-source library:
#include "tz.h"
#include <iostream>
int
main()
{
using namespace date;
using namespace std::chrono_literals;
try
{
auto zone = locate_zone("America/New_York");
zone->to_sys(local_days{mar/13/2016} + 2h + 30min);
}
catch (const std::exception& e)
{
std::cout << e.what() << '\n';
}
}
The output of this program is:
2016-03-13 02:30 is in a gap between
2016-03-13 02:00:00 EST and
2016-03-13 03:00:00 EDT which are both equivalent to
2016-03-13 07:00:00 UTC
In short, this program attempts to translate a locale date/time of 2016-03-13 02:30:00 to UTC using the timezone "America/New_York". The translation throws an exception because the local time doesn't exist. An exception is also thrown (with a different error message), if the local time is ambiguous, such as when setting the local clock back from daylight saving.
The library also provides syntax for avoiding these exceptions if that is the desire.
This works on VS-2013, VS-2015, clang, and gcc. It requires C++11, C++14 or C++1z.
The link above points to the documentation. Here is the github repository:
https://github.com/HowardHinnant/date