Final Platform Layer 1.0.0
Loading...
Searching...
No Matches
Query Date & Time

FPL provides a couple of functions for querying and constructing calendar date and time values.
A date time is stored in the fplDateTime structure, which holds the Unix epoch (seconds since 1970-01-01), additional milliseconds and the UTC offset in minutes.

Note
Pre-1970 dates are not supported. The epoch field is unsigned and fplDateTimeCreate() rejects any year below 1970.

For pure delta/profiling measurements, use the functions described in Time Measurement & Profiling instead.

Query the current date and time

You can query the current date and time by calling fplDateTimeQuery() and passing a fplDateTimeType value.
Pass fplDateTimeType_UTC to get the time in UTC (+0) or fplDateTimeType_Local to get the local time including the current UTC offset.

// Query the current local date time
// Query the current UTC date time
fpl_platform_api fplDateTime fplDateTimeQuery(const fplDateTimeType type)
Gets the current date and time in the specified format (UTC or local).
@ fplDateTimeType_Local
Local type (+/- offset).
@ fplDateTimeType_UTC
UTC type (+0).
Stores a date and time with milliseconds, including the UTC offset.

The returned fplDateTime is not directly human readable - it stores the epoch, milliseconds and UTC offset only.
To get the individual date and time components, use fplFormatDateTime() (see Extract the date and time components).

Extract the date and time components

To break a fplDateTime into its individual fields (year, month, day, hour, etc.), call fplFormatDateTime() .
It returns a fplDateTimeResult, which contains the year, month, day, hour, minute, second and millisecond.

The fplDateTimeType argument controls whether the components are computed in UTC or local time.

// Compute the individual components in local time
fplConsoleFormatOut("%04d-%02d-%02d %02d:%02d:%02d.%03d\n",
fields.year, fields.month, fields.day,
fields.hour, fields.minute, fields.second, fields.millisecond);
fpl_common_api void fplConsoleFormatOut(const char *format,...)
Writes the given formatted text to the standard output console buffer.
fpl_platform_api fplDateTimeResult fplFormatDateTime(const fplDateTime dateTime, const fplDateTimeType type)
Formats the date time into the specified format as a fplDateTimeResult.
Stores the components for a date and time, that may be computed from a date time stamp.
uint8_t minute
Minute in range of 0-59.
uint16_t year
Year in range of 0-9999.
uint8_t month
Month in range of 1-12.
uint8_t second
Second in range of 0-59.
uint8_t hour
Hour in range of 0-23.
uint8_t day
Day in range of 1-31.
uint16_t millisecond
Millisecond in range of 0-999.

Create a date and time

You can construct a fplDateTime from individual components by calling fplDateTimeCreate() .
It takes the year, month, day, hour, minute, second, millisecond and the UTC offset in minutes.

The result is returned as a fplDateTimeCreationResult. Always check the success field before using the resulting date time.
If the creation fails, the errors field contains a combination of fplDateTimeErrors flags describing which component was invalid.

// Create the date time 2026-05-16 13:45:00.000 in UTC (+0)
fplDateTimeCreationResult result = fplDateTimeCreate(2026, 5, 16, 13, 45, 0, 0, 0);
if (result.success) {
fplDateTime dateTime = result.dateTime;
// Do something with the date time
} else {
// The year was out of range (expected 1970 or higher)
}
}
fpl_common_api fplDateTimeCreationResult fplDateTimeCreate(const uint16_t year, const uint8_t month, const uint8_t day, const uint8_t hour, const uint8_t minute, const uint8_t second, const uint16_t millisecond, const int32_t utcOffset)
Creates a date time from the specified date time components and UTC offset.
@ fplDateTimeErrors_InvalidYear
Invalid year, expected range is 1970 or higher.
Stores the result of a date time creation.
fplDateTimeErrors errors
The creation error flags.
bool success
A value indicating whether the creation was successful or not.
fplDateTime dateTime
The resulting date time.
Note
If invalid arguments are passed, an empty date time is returned and success is set to false.

Notes