KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
Loading...
Searching...
No Matches
DateTimeUtil Class Reference

DateTimeUtil. More...

#include <datetimeutil.h>

Static Public Member Functions

static QDateTime fromISOString (const QString &date)
 Parse an ISO-8601 string into a UTC QDateTime.
 
static QDateTime fromStandardString (const QString &date)
 Parse a MySQL-style "yyyy-MM-dd hh:mm:ss.zzz" string into a QDateTime.
 
static QDateTime fromSquashedString (const QString &date)
 Parse a compact "yyyyMMddhhmmsszzz" string into a QDateTime.
 
static QDateTime fromString (const QString &date)
 Parse a date/time string, trying multiple known formats.
 
static QDateTime fromVariant (const QVariant &date)
 Parse a QVariant containing a date/time string or QDateTime.
 
static QString toStandardString (const QDateTime &date, bool milliseconds=true)
 Format a QDateTime as a MySQL-style string.
 
static QString toISOString (const QDateTime &date)
 Format a QDateTime as an ISO-8601 Zulu string.
 
static QString toSquashedString (const QDateTime &date)
 Format a QDateTime as a compact squashed string.
 
static QString toStandardTimeString (const QDateTime &date)
 Format the time portion of a QDateTime as "HH:mm:ss.zzz".
 
static QString toStandardDateString (const QDateTime &date)
 Format the date portion of a QDateTime as "yyyy-MM-dd".
 
static QString currentToISOString ()
 Return the current UTC time as an ISO-8601 Zulu string.
 
static QString currentToStandardString (bool milliseconds=true)
 Return the current UTC time as a MySQL-style string.
 
static QString currentToSquashedString ()
 Return the current UTC time as a compact squashed string.
 

Detailed Description

DateTimeUtil.

Some static helper methods for converting date/times to and from strings.

In general, on of two formats are preferred:

  1. ISO-8601 ZULU e.g. 2021-09-17T05:30:00.123Z
  2. MySQL e.g. 2021-09-17 05:30:00.123

Stephen Punak, September 17 2020

Static helper methods for parsing and formatting QDateTime values.

Supports ISO-8601 Zulu (e.g. 2021-09-17T05:30:00.123Z) and MySQL-style (e.g. 2021-09-17 05:30:00.123) formats as well as a compact "squashed" form.

Definition at line 26 of file datetimeutil.h.

Member Function Documentation

◆ currentToISOString()

static QString DateTimeUtil::currentToISOString ( )
inlinestatic

Return the current UTC time as an ISO-8601 Zulu string.

Returns
Current UTC timestamp string

Definition at line 112 of file datetimeutil.h.

◆ currentToSquashedString()

static QString DateTimeUtil::currentToSquashedString ( )
inlinestatic

Return the current UTC time as a compact squashed string.

Returns
Current UTC timestamp in squashed format

Definition at line 128 of file datetimeutil.h.

◆ currentToStandardString()

static QString DateTimeUtil::currentToStandardString ( bool  milliseconds = true)
inlinestatic

Return the current UTC time as a MySQL-style string.

Parameters
millisecondsWhether to include milliseconds (default true)
Returns
Current UTC timestamp string

Definition at line 119 of file datetimeutil.h.

◆ fromISOString()

static QDateTime DateTimeUtil::fromISOString ( const QString &  date)
inlinestatic

Parse an ISO-8601 string into a UTC QDateTime.

Parameters
dateISO-8601 date/time string with milliseconds
Returns
Parsed UTC QDateTime, or invalid QDateTime on error

Definition at line 34 of file datetimeutil.h.

◆ fromSquashedString()

static QDateTime DateTimeUtil::fromSquashedString ( const QString &  date)
static

Parse a compact "yyyyMMddhhmmsszzz" string into a QDateTime.

Parameters
dateSquashed format date/time string
Returns
Parsed QDateTime, or invalid QDateTime on error

◆ fromStandardString()

static QDateTime DateTimeUtil::fromStandardString ( const QString &  date)
static

Parse a MySQL-style "yyyy-MM-dd hh:mm:ss.zzz" string into a QDateTime.

Parameters
dateMySQL format date/time string
Returns
Parsed QDateTime, or invalid QDateTime on error

◆ fromString()

static QDateTime DateTimeUtil::fromString ( const QString &  date)
static

Parse a date/time string, trying multiple known formats.

Parameters
dateDate/time string in any supported format
Returns
Parsed QDateTime, or invalid QDateTime if no format matches

◆ fromVariant()

static QDateTime DateTimeUtil::fromVariant ( const QVariant &  date)
static

Parse a QVariant containing a date/time string or QDateTime.

Parameters
dateVariant holding a date/time value
Returns
Parsed QDateTime, or invalid QDateTime on error

◆ toISOString()

static QString DateTimeUtil::toISOString ( const QDateTime &  date)
inlinestatic

Format a QDateTime as an ISO-8601 Zulu string.

Parameters
dateDate/time to format
Returns
Formatted string, e.g. "2021-09-17T05:30:00.123Z"

Definition at line 85 of file datetimeutil.h.

◆ toSquashedString()

static QString DateTimeUtil::toSquashedString ( const QDateTime &  date)
inlinestatic

Format a QDateTime as a compact squashed string.

Parameters
dateDate/time to format
Returns
Formatted string, e.g. "20210917053000123"

Definition at line 92 of file datetimeutil.h.

◆ toStandardDateString()

static QString DateTimeUtil::toStandardDateString ( const QDateTime &  date)
inlinestatic

Format the date portion of a QDateTime as "yyyy-MM-dd".

Parameters
dateDate/time whose date portion to format
Returns
Formatted date string

Definition at line 106 of file datetimeutil.h.

◆ toStandardString()

static QString DateTimeUtil::toStandardString ( const QDateTime &  date,
bool  milliseconds = true 
)
inlinestatic

Format a QDateTime as a MySQL-style string.

Parameters
dateDate/time to format
millisecondsWhether to include milliseconds (default true)
Returns
Formatted string, e.g. "2021-09-17 05:30:00.123"

Definition at line 75 of file datetimeutil.h.

◆ toStandardTimeString()

static QString DateTimeUtil::toStandardTimeString ( const QDateTime &  date)
inlinestatic

Format the time portion of a QDateTime as "HH:mm:ss.zzz".

Parameters
dateDate/time whose time portion to format
Returns
Formatted time string

Definition at line 99 of file datetimeutil.h.


The documentation for this class was generated from the following file: