MCPcopy Create free account
hub / github.com/SmingHub/Sming / showTime

Function showTime

samples/Basic_DateTime/app/application.cpp:14–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12DEFINE_FSTR_LOCAL(commandPrompt, "Enter Unix timestamp: ");
13
14void showTime(const DateTime& dt)
15{
16 auto printFormat = [&dt](const String& fmt, const String& msg) -> void {
17 Serial << fmt << ' ' << msg << ": " << dt.format(fmt) << endl;
18 };
19
20 // Non-time
21 printFormat("%%", F("Percent sign"));
22 printFormat("%n", F("New-line character"));
23 printFormat("|<", F("Horizontal-tab character: >|"));
24 // Year
25 printFormat("%Y", F("Full year (YYYY)"));
26 printFormat("%C", F("Year, first two digits (00-99)"));
27 printFormat("%y", F("Year, last two digits (00-99)"));
28 // Month
29 printFormat("%B", F("Full month name (e.g. June)"));
30 printFormat("%b", F("Abbreviated month name (e.g. Jun)"));
31 printFormat("%h", F("Abbreviated month name (e.g. Jun)"));
32 printFormat("%m", F("Month as a decimal number (01-12)"));
33 // Week
34 printFormat("%U", F("Week number with the first Sunday as the first day of week one (00-53)"));
35 printFormat("%W", F("Week number with the first Monday as the first day of week one (00-53)"));
36 printFormat("%V", F("ISO 8601 week number (01-53)"));
37 // Day
38 printFormat("%j", F("Day of the year (001-366)"));
39 printFormat("%d", F("Day of the month, zero-padded (01-31)"));
40 printFormat("%e", F("Day of the month, space-padded ( 1-31)"));
41 printFormat("%A", F("Full weekday name (e.g. Monday)"));
42 printFormat("%a", F("Abbreviated weekday name (e.g. Mon)"));
43 printFormat("%w", F("Weekday as a decimal number with Sunday as 0 (0-6)"));
44 printFormat("%u", F("ISO 8601 weekday as number with Monday as 1 (1-7)"));
45 // Hour
46 printFormat("%p", F("Meridiem (AM|PM)"));
47 printFormat("%H", F("Hour in 24h format (00-23)"));
48 printFormat("%I", F("Hour in 12h format (01-12)"));
49 // Minute
50 printFormat("%M", F("Minute (00-59)"));
51 // Second
52 printFormat("%S", F("Second (00-61)"));
53 // Formatted strings
54 printFormat("%R", F("24-hour time (HH:MM)"));
55 printFormat("%r", F("12-hour time (hh:MM:SS AM)"));
56 printFormat("%c", F("Locale date and time"));
57 printFormat("%D", F("US short date (MM/DD/YY)"));
58 printFormat("%F", F("ISO 8601 date (YYYY-MM-DD)"));
59 printFormat("%T", F("ISO 8601 time (HH:MM:SS)"));
60 printFormat("%x", F("Locale date"));
61 printFormat("%X", F("Locale time"));
62
63 auto print = [](const String& tag, const String& value) { Serial << tag << ": " << value << endl; };
64
65 // HTTP date
66 print(F("toHTTPDate"), dt.toHTTPDate());
67 DateTime dt2;
68 dt2.fromHttpDate(dt.toHTTPDate());
69 print(F("fromHTTPDate"), dt2.toHTTPDate());
70 print(F("toFullDateTimeString"), dt.toFullDateTimeString());
71 print(F("toISO8601"), dt.toISO8601());

Callers 1

onRxFunction · 0.85

Calls 9

toHTTPDateMethod · 0.80
fromHttpDateMethod · 0.80
toFullDateTimeStringMethod · 0.80
toShortDateStringMethod · 0.80
toShortTimeStringMethod · 0.80
FFunction · 0.50
printFunction · 0.50
formatMethod · 0.45
toISO8601Method · 0.45

Tested by

no test coverage detected