Meszias

Arduino read build date and time on tmElements_t

Jul 27th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <Time.h>
  2. #include <string.h>
  3.  
  4. void readBuildDate(tmElements_t * tm){
  5.     char *token = strtok(__DATE__, " ");
  6.     static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
  7.     tm->Month = (strstr(month_names, token)-month_names)/3+1;
  8.     token = strtok(NULL, " ");    
  9.     tm->Day = atoi(token);
  10.     token = strtok(NULL, " ");    
  11.     tm->Year = CalendarYrToTm(atoi(token));
  12.     token = strtok(__TIME__, ":");
  13.     tm->Hour = atoi(token);    
  14.     token = strtok(NULL, ":");
  15.     tm->Minute = atoi(token);    
  16.     token = strtok(NULL, ":");
  17.     tm->Second = atoi(token);
  18. }
  19.  
  20. void setup(){
  21.         // USAGE:
  22.     tmElements_t btm;
  23.     readBuildDate(&btm);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment