21#if defined(PICO_RP2040)
22#include "hardware/rtc.h"
23#elif defined(PICO_RP2350)
24#include "pico/aon_timer.h"
30#if defined(PICO_RP2040)
32 rtc_get_datetime(&dt);
34 t.tm_year = dt.year - 1900;
35 t.tm_mon = dt.month - 1;
41#elif defined(PICO_RP2350)
44 aon_timer_get_time(&t);
54 localtime_r(&t, &out);
59#if defined(PICO_RP2040)
60datetime_t PicoTime::nowDatetime()
63 rtc_get_datetime(&dt);
71 struct tm t =
nowTm();
73 snprintf(buf,
sizeof(buf),
"%02d:%02d:%02d", t.tm_hour, t.tm_min, t.tm_sec);
74 return std::string(buf);
78struct tm
PicoTime::todayAt(const struct tm *hhmmss)
80 struct tm now = nowTm();
82 .tm_sec = hhmmss->tm_sec,
83 .tm_min = hhmmss->tm_min,
84 .tm_hour = hhmmss->tm_hour,
85 .tm_mday = now.tm_mday,
87 .tm_year = now.tm_year,
105 strftime(buf,
sizeof(buf),
"%Y-%m-%d %H:%M:%S", &t);
106 return std::string(buf);
119 localtime_r(&t, &tm);
127 strftime(buf,
sizeof(buf),
"%Y-%m-%d %H:%M:%S", t);
134 localtime_r(&t, &tm);
136 strftime(buf,
sizeof(buf),
"%Y-%m-%dT%H:%M:%S", &tm);
137 return std::string(buf);
141#if defined(PICO_RP2040)
144 printf(
"%04d-%02d-%02d %02d:%02d:%02d\n",
145 dt->year, dt->month, dt->day,
146 dt->hour, dt->min, dt->sec);
Time utility functions for the Pico platform (RP2040/RP2350).
Cross-platform time utilities for RP2040 and RP2350.
static void printNow()
Print the current time to stdout.
static struct tm todayAt(const struct tm *hhmmss)
Construct today's date with a specific time-of-day.
static std::string formatIso8601(time_t t)
static struct tm nowTm()
Get the current local time as struct tm.
static time_t now()
Get the current epoch time using platform RTC or AON.
static time_t todayAtTimeT(const struct tm *hhmmss)
Convert a tm with today's date and time to epoch.
static void print(time_t t)
Print a given UNIX timestamp to stdout.
static std::string todayHhMmSsString(const struct tm *hhmmss)
Convert a time-of-day to a string for today.
static std::string getNowHhMmSs()
Get the current time as a datetime_t.