I'm trying to convert the string produced from the __DATE__
macro into a time_t
. I don't need a full-blown date/time parser, something that only handles the format of the __DATE__
macro would be great.
A preprocessor method would be nifty, but a function would work just as well. If it's relevant, I'm using MSVC.
Here is how I modified your sample to use with mbed for Arm32 micro controllers in C++.
See: https://developer.mbed.org/users/joeata2wh/code/compile_time_to_system_time/ for complete code. Also see https://developer.mbed.org/users/joeata2wh/code/xj-Init-clock-to-compile-time-if-not-alr/ for an example of how I use it to initialize a clock chip based on the compile time.
Edit: the corrected function should look something like this:
Basing on the description given at gcc.gnu.org the build date can be obtain at the compilation time using following macros.
Answer here.
Spec for the format of DATE is here.
I don't know if any other Arduino hackers will stumble upon this question, but I found @JerryCoffin's answer to be quite helpful in solving this problem for my project. Here is a complete example you can paste into Arduino. It uses the Time lib referenced here.
Here are the Serial Terminal results...
If all you want is to use the
__DATE__
and you don't need atime_t
ortmElements_t
object, the code can be much simpler.Here are the Serial Terminal results...
Bruno's response was very useful for my Arduino Project. Here is a version with both __DATE__ and __TIME__