NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
datetime类 参考

日期时间类 更多...

#include <datetime.hpp>

类 datetime 继承关系图:
[图例]

Public 类型

using date_type = _NEFORCE date::date_type
 日期分量类型
using time_type = _NEFORCE time::time_type
 时间分量类型

Public 成员函数

constexpr datetime (const date_type year, const date_type month, const date_type day, const time_type hour, const time_type minute, const time_type second) noexcept
 从日期和时间构造
constexpr datetime (const date_type year, const date_type month, const date_type day, const time_type hour, const time_type minute, const time_type second, const int64_t offset) noexcept
 从日期、时间和时区构造
constexpr datetime (const _NEFORCE date &date, const _NEFORCE time &time) noexcept
 从日期和时间对象构造
constexpr datetime (const _NEFORCE date &date, const _NEFORCE time &time, const int64_t offset) noexcept
 从日期、时间对象和时区构造
constexpr datetime (const _NEFORCE date &date) noexcept
 从日期构造(时间部分为00:00:00)
constexpr datetime (const _NEFORCE time &time) noexcept
 从时间构造(日期部分为1970-01-01)
constexpr datetime (_NEFORCE date &&date) noexcept
 从日期构造(时间部分为00:00:00)
constexpr datetime (_NEFORCE time &&time) noexcept
 从时间构造(日期部分为1970-01-01)
constexpr datetime (_NEFORCE date &&date, _NEFORCE time &&time) noexcept
 从日期和时间对象移动构造
constexpr datetime (_NEFORCE date &&date, _NEFORCE time &&time, const int64_t offset) noexcept
 从日期、时间对象和时区移动构造
constexpr bool is_valid () const noexcept
 检查时间是否有效
constexpr datetimeoperator= (const _NEFORCE date &date) noexcept
 从日期赋值
constexpr datetimeoperator= (_NEFORCE date &&date) noexcept
 从日期移动赋值
constexpr datetimeoperator= (const _NEFORCE time &time) noexcept
 从时间赋值
constexpr datetimeoperator= (_NEFORCE time &&time) noexcept
 从时间移动赋值
constexpr const _NEFORCE datedate () const noexcept
 获取日期部分
constexpr const _NEFORCE timetime () const noexcept
 获取时间部分
constexpr time_type hours () const noexcept
 获取小时
constexpr time_type minutes () const noexcept
 获取分钟
constexpr time_type seconds () const noexcept
 获取秒
constexpr date_type year () const noexcept
 获取年份
constexpr date_type month () const noexcept
 获取月份
constexpr date_type day () const noexcept
 获取日期
constexpr bool has_timezone () const noexcept
 检查是否有时区信息
constexpr int64_t offset_seconds () const noexcept
 获取时区偏移
constexpr void clear () noexcept
 重置为纪元起始时间
constexpr bool equal_to (const datetime &other) const noexcept
 相等比较
constexpr bool less_than (const datetime &other) const noexcept
 小于比较
constexpr datetimeoperator+= (const int64_t seconds)
 加秒数
constexpr datetimeoperator-= (const int64_t seconds) noexcept
 减秒数
constexpr datetime operator+ (const int64_t seconds) const noexcept
 加秒数
constexpr datetime operator- (const int64_t seconds) const noexcept
 减秒数
constexpr datetimeoperator++ ()
 前置递增(加1秒)
constexpr datetime operator++ (int)
 后置递增(加1秒)
constexpr datetimeoperator-- ()
 前置递减(减1秒)
constexpr datetime operator-- (int)
 后置递减(减1秒)
constexpr time_type operator- (const datetime &other) const noexcept
 时间差(秒数)
constexpr string to_offset_string () const
 转换为时区偏移字符串
constexpr datetime to_UTC () const noexcept
 转换为UTC时间
constexpr string to_RFC3339 () const
 转换为 RFC 3339
constexpr bool try_parse_RFC3339 (const string_view view) noexcept
 尝试解析 RFC 3339
constexpr string to_RFC1123 () const
 转换为 RFC 1123
constexpr bool try_parse_RFC1123 (const string_view view) noexcept
 尝试解析 RFC 1123
constexpr string to_ISO8601 () const
 转换为 ISO 8601
constexpr bool try_parse_ISO8601 (const string_view view) noexcept
 尝试解析 ISO 8601
constexpr string to_string () const
 转换为简单格式
constexpr size_t to_hash () const noexcept
 计算哈希值
constexpr void swap (datetime &other) noexcept
 交换两个日期时间
Public 成员函数 继承自 iobject< datetime >
constexpr bool try_parse (const string_view str) noexcept
 尝试从字符串解析对象
Public 成员函数 继承自 istringify< datetime >
constexpr string to_string () const
 转换为字符串
Public 成员函数 继承自 icomparable< datetime >
constexpr bool operator== (const datetime &rhs) const noexcept(noexcept(derived().equal_to(rhs)))
 相等比较运算符
constexpr bool operator!= (const datetime &rhs) const noexcept(noexcept(!(derived().equal_to(rhs))))
 不等比较运算符
constexpr bool operator< (const datetime &rhs) const noexcept(noexcept(derived().less_than(rhs)))
 小于比较运算符
constexpr bool operator> (const datetime &rhs) const noexcept(noexcept(rhs.less_than(derived())))
 大于比较运算符
constexpr bool operator<= (const datetime &rhs) const noexcept(noexcept(!(rhs.less_than(derived()))))
 小于等于比较运算符
constexpr bool operator>= (const datetime &rhs) const noexcept(noexcept(!(derived().less_than(rhs))))
 大于等于比较运算符
Public 成员函数 继承自 ihashable< datetime >
constexpr size_t to_ihash () const noexcept(noexcept(derived().to_hash()))
 获取对象的哈希值

静态 Public 成员函数

static constexpr datetime epoch () noexcept
 获取纪元起始时间(1970-01-01 00:00:00 UTC)
static datetime now () noexcept
 获取当前本地时间
static constexpr datetime from_UTC (const datetime &utc, const int32_t offset=0) noexcept
 从UTC时间转换为本地时间
static constexpr datetime parse_RFC3339 (const string_view view)
 解析 RFC 3339
static constexpr datetime parse_RFC1123 (string_view view)
 解析 RFC 1123
static constexpr datetime parse_ISO8601 (const string_view view)
 解析 ISO 8601
static constexpr datetime parse (const string_view view)
 解析简单格式
静态 Public 成员函数 继承自 iobject< datetime >
static constexpr datetime parse (const string_view str)
 从字符串解析对象

详细描述

日期时间类

组合日期和时间,支持时区处理。 提供多种格式的解析和格式化:

  • ISO格式(YYYY-MM-DDTHH:MM:SS)
  • ISO带时区(YYYY-MM-DDTHH:MM:SS±HH:MM 或 Z)
  • GMT格式(RFC 1123)
  • 简单格式(YYYY-MM-DD HH:MM:SS)

在文件 datetime.hpp734 行定义.

构造及析构函数说明

◆ datetime() [1/10]

datetime::datetime ( const date_type year,
const date_type month,
const date_type day,
const time_type hour,
const time_type minute,
const time_type second )
inlineexplicitconstexprnoexcept

从日期和时间构造

参数
year年份
month月份
day日期
hour小时
minute分钟
second

在文件 datetime.hpp781 行定义.

引用了 day(), month() , 以及 year().

◆ datetime() [2/10]

datetime::datetime ( const date_type year,
const date_type month,
const date_type day,
const time_type hour,
const time_type minute,
const time_type second,
const int64_t offset )
inlineexplicitconstexprnoexcept

从日期、时间和时区构造

参数
year年份
month月份
day日期
hour小时
minute分钟
second
offset时区偏移(秒)

在文件 datetime.hpp796 行定义.

引用了 day(), month() , 以及 year().

◆ datetime() [3/10]

datetime::datetime ( const _NEFORCE date & date,
const _NEFORCE time & time )
inlineexplicitconstexprnoexcept

从日期和时间对象构造

参数
date日期对象
time时间对象

在文件 datetime.hpp808 行定义.

引用了 date() , 以及 time().

◆ datetime() [4/10]

datetime::datetime ( const _NEFORCE date & date,
const _NEFORCE time & time,
const int64_t offset )
inlineexplicitconstexprnoexcept

从日期、时间对象和时区构造

参数
date日期对象
time时间对象
offset时区偏移(秒)

在文件 datetime.hpp818 行定义.

引用了 date() , 以及 time().

◆ datetime() [5/10]

datetime::datetime ( const _NEFORCE date & date)
inlineexplicitconstexprnoexcept

从日期构造(时间部分为00:00:00)

参数
date日期对象

在文件 datetime.hpp828 行定义.

引用了 date().

◆ datetime() [6/10]

datetime::datetime ( const _NEFORCE time & time)
inlineexplicitconstexprnoexcept

从时间构造(日期部分为1970-01-01)

参数
time时间对象

在文件 datetime.hpp835 行定义.

引用了 time().

◆ datetime() [7/10]

datetime::datetime ( _NEFORCE date && date)
inlineexplicitconstexprnoexcept

从日期构造(时间部分为00:00:00)

参数
date日期对象

在文件 datetime.hpp842 行定义.

引用了 date().

◆ datetime() [8/10]

datetime::datetime ( _NEFORCE time && time)
inlineexplicitconstexprnoexcept

从时间构造(日期部分为1970-01-01)

参数
time时间对象

在文件 datetime.hpp851 行定义.

引用了 time().

◆ datetime() [9/10]

datetime::datetime ( _NEFORCE date && date,
_NEFORCE time && time )
inlineexplicitconstexprnoexcept

从日期和时间对象移动构造

参数
date日期对象
time时间对象

在文件 datetime.hpp861 行定义.

引用了 date() , 以及 time().

◆ datetime() [10/10]

datetime::datetime ( _NEFORCE date && date,
_NEFORCE time && time,
const int64_t offset )
inlineexplicitconstexprnoexcept

从日期、时间对象和时区移动构造

参数
date日期对象
time时间对象
offset时区偏移(秒)

在文件 datetime.hpp874 行定义.

引用了 date() , 以及 time().

成员函数说明

◆ date()

const _NEFORCE date & datetime::date ( ) const
inlinenodiscardconstexprnoexcept

◆ day()

date_type datetime::day ( ) const
inlinenodiscardconstexprnoexcept

获取日期

返回
日期

在文件 datetime.hpp977 行定义.

被这些函数引用 datetime(), datetime() , 以及 parse_RFC1123().

◆ epoch()

constexpr datetime datetime::epoch ( )
inlinestaticnodiscardconstexprnoexcept

获取纪元起始时间(1970-01-01 00:00:00 UTC)

返回
纪元起始时间

在文件 datetime.hpp995 行定义.

被这些函数引用 timestamp::timestamp() , 以及 timestamp::to_datetime().

◆ from_UTC()

constexpr datetime datetime::from_UTC ( const datetime & utc,
const int32_t offset = 0 )
inlinestaticconstexprnoexcept

从UTC时间转换为本地时间

参数
utcUTC时间
offset本地时区偏移(秒)
返回
本地时间

在文件 datetime.hpp1188 行定义.

引用了 to_UTC().

◆ has_timezone()

bool datetime::has_timezone ( ) const
inlinenodiscardconstexprnoexcept

检查是否有时区信息

返回
是否有时区

在文件 datetime.hpp983 行定义.

◆ hours()

time_type datetime::hours ( ) const
inlinenodiscardconstexprnoexcept

获取小时

返回
小时

在文件 datetime.hpp947 行定义.

被这些函数引用 parse_RFC3339() , 以及 to_offset_string().

◆ is_valid()

bool datetime::is_valid ( ) const
inlinenodiscardconstexprnoexcept

检查时间是否有效

返回
是否有效

在文件 datetime.hpp887 行定义.

◆ minutes()

time_type datetime::minutes ( ) const
inlinenodiscardconstexprnoexcept

获取分钟

返回
分钟

在文件 datetime.hpp953 行定义.

被这些函数引用 parse_RFC3339() , 以及 to_offset_string().

◆ month()

date_type datetime::month ( ) const
inlinenodiscardconstexprnoexcept

获取月份

返回
月份

在文件 datetime.hpp971 行定义.

被这些函数引用 datetime() , 以及 datetime().

◆ now()

datetime datetime::now ( )
staticnodiscardnoexcept

获取当前本地时间

返回
当前本地时间

被这些函数引用 http_session::age(), http_session::idle_time() , 以及 timestamp::now().

◆ offset_seconds()

int64_t datetime::offset_seconds ( ) const
inlinenodiscardconstexprnoexcept

获取时区偏移

返回
时区偏移(秒)

在文件 datetime.hpp989 行定义.

◆ operator+()

datetime datetime::operator+ ( const int64_t seconds) const
inlineconstexprnoexcept

加秒数

参数
seconds秒数
返回
新时间

在文件 datetime.hpp1103 行定义.

引用了 seconds().

◆ operator+=()

datetime & datetime::operator+= ( const int64_t seconds)
inlineconstexpr

加秒数

参数
seconds秒数
返回
自身引用

在文件 datetime.hpp1044 行定义.

引用了 seconds() , 以及 time().

◆ operator-() [1/2]

time_type datetime::operator- ( const datetime & other) const
inlineconstexprnoexcept

时间差(秒数)

参数
other另一个时间
返回
相差的秒数

在文件 datetime.hpp1153 行定义.

引用了 to_UTC().

◆ operator-() [2/2]

datetime datetime::operator- ( const int64_t seconds) const
inlineconstexprnoexcept

减秒数

参数
seconds秒数
返回
新时间

在文件 datetime.hpp1114 行定义.

引用了 seconds().

◆ operator-=()

datetime & datetime::operator-= ( const int64_t seconds)
inlineconstexprnoexcept

减秒数

参数
seconds秒数
返回
自身引用

在文件 datetime.hpp1074 行定义.

引用了 seconds() , 以及 time().

◆ operator=() [1/4]

datetime & datetime::operator= ( _NEFORCE date && date)
inlineconstexprnoexcept

从日期移动赋值

参数
date日期对象
返回
自身引用

在文件 datetime.hpp904 行定义.

引用了 date().

◆ operator=() [2/4]

datetime & datetime::operator= ( _NEFORCE time && time)
inlineconstexprnoexcept

从时间移动赋值

参数
time时间对象
返回
自身引用

在文件 datetime.hpp925 行定义.

引用了 time().

◆ operator=() [3/4]

datetime & datetime::operator= ( const _NEFORCE date & date)
inlineconstexprnoexcept

从日期赋值

参数
date日期对象
返回
自身引用

在文件 datetime.hpp894 行定义.

引用了 date().

◆ operator=() [4/4]

datetime & datetime::operator= ( const _NEFORCE time & time)
inlineconstexprnoexcept

从时间赋值

参数
time时间对象
返回
自身引用

在文件 datetime.hpp915 行定义.

引用了 time().

◆ parse()

constexpr datetime datetime::parse ( const string_view view)
inlinestaticnodiscardconstexpr

解析简单格式

参数
view格式为 YYYY-MM-DD HH:MM:SS 的字符串
返回
解析得到的日期时间
异常
value_exception格式错误时抛出

在文件 datetime.hpp1426 行定义.

引用了 date(), date::parse(), time::parse(), basic_string_view< CharT, Traits >::size(), basic_string_view< CharT, Traits >::substr() , 以及 time().

◆ parse_ISO8601()

constexpr datetime datetime::parse_ISO8601 ( const string_view view)
inlinestaticnodiscardconstexpr

解析 ISO 8601

参数
viewISO 8601 格式字符串
返回
解析得到的日期时间
异常
value_exception格式错误时抛出

在文件 datetime.hpp1384 行定义.

引用了 date(), date::parse(), time::parse(), basic_string_view< CharT, Traits >::size(), basic_string_view< CharT, Traits >::substr() , 以及 time().

被这些函数引用 try_parse_ISO8601().

◆ parse_RFC1123()

constexpr datetime datetime::parse_RFC1123 ( string_view view)
inlinestaticnodiscardconstexpr

解析 RFC 1123

参数
viewRFC 1123 格式字符串
返回
解析得到的日期时间
异常
value_exception格式错误时抛出

在文件 datetime.hpp1324 行定义.

引用了 day(), basic_string_view< CharT, Traits >::head(), basic_string_view< CharT, Traits >::remove_prefix(), basic_string_view< CharT, Traits >::size(), basic_string_view< CharT, Traits >::substr() , 以及 year().

被这些函数引用 try_parse_RFC1123().

◆ parse_RFC3339()

constexpr datetime datetime::parse_RFC3339 ( const string_view view)
inlinestaticnodiscardconstexpr

解析 RFC 3339

参数
viewRFC 3339 格式字符串
返回
解析得到的日期时间
异常
value_exception格式错误或缺少时区信息时抛出

在文件 datetime.hpp1233 行定义.

引用了 date(), hours(), minutes(), date::parse(), time::parse(), sign(), basic_string_view< CharT, Traits >::size(), basic_string_view< CharT, Traits >::substr() , 以及 time().

被这些函数引用 try_parse_RFC3339().

◆ seconds()

time_type datetime::seconds ( ) const
inlinenodiscardconstexprnoexcept

获取秒

返回

在文件 datetime.hpp959 行定义.

被这些函数引用 operator+(), operator+=(), operator-() , 以及 operator-=().

◆ swap()

void datetime::swap ( datetime & other)
inlineconstexprnoexcept

交换两个日期时间

参数
other另一个日期时间

在文件 datetime.hpp1447 行定义.

引用了 swap().

◆ time()

const _NEFORCE time & datetime::time ( ) const
inlinenodiscardconstexprnoexcept

◆ to_hash()

size_t datetime::to_hash ( ) const
inlinenodiscardconstexprnoexcept

计算哈希值

返回
哈希值

在文件 datetime.hpp1439 行定义.

◆ to_ISO8601()

string datetime::to_ISO8601 ( ) const
inlinenodiscardconstexpr

转换为 ISO 8601

返回
格式为 YYYY-MM-DDTHH:MM:SS

在文件 datetime.hpp1374 行定义.

◆ to_offset_string()

string datetime::to_offset_string ( ) const
inlinenodiscardconstexpr

转换为时区偏移字符串

返回
格式为 ±HH:MM 或 "Z"

在文件 datetime.hpp1167 行定义.

引用了 format(), hours(), minutes() , 以及 sign().

被这些函数引用 to_RFC3339().

◆ to_RFC1123()

string datetime::to_RFC1123 ( ) const
inlinenodiscardconstexpr

转换为 RFC 1123

返回
格式为 "Wed, 21 Dec 2022 10:00:00 GMT"

在文件 datetime.hpp1295 行定义.

引用了 date(), format() , 以及 time().

◆ to_RFC3339()

string datetime::to_RFC3339 ( ) const
inlinenodiscardconstexpr

转换为 RFC 3339

返回
格式为 YYYY-MM-DDTHH:MM:SSZ 或 YYYY-MM-DDTHH:MM:SS±HH:MM
注解
RFC 3339 要求必须包含时区信息

在文件 datetime.hpp1219 行定义.

引用了 to_offset_string().

◆ to_string()

string datetime::to_string ( ) const
inlinenodiscardconstexpr

转换为简单格式

返回
格式为 YYYY-MM-DD HH:MM:SS

在文件 datetime.hpp1416 行定义.

◆ to_UTC()

datetime datetime::to_UTC ( ) const
inlinenodiscardconstexprnoexcept

转换为UTC时间

返回
UTC时间

在文件 datetime.hpp1203 行定义.

被这些函数引用 from_UTC(), operator-() , 以及 timestamp::timestamp().

◆ try_parse_ISO8601()

bool datetime::try_parse_ISO8601 ( const string_view view)
inlineconstexprnoexcept

尝试解析 ISO 8601

参数
viewISO 8601 格式字符串
返回
是否解析成功

在文件 datetime.hpp1402 行定义.

引用了 parse_ISO8601() , 以及 swap().

被这些函数引用 toml_datetime::toml_datetime() , 以及 yaml_timestamp::yaml_timestamp().

◆ try_parse_RFC1123()

bool datetime::try_parse_RFC1123 ( const string_view view)
inlineconstexprnoexcept

尝试解析 RFC 1123

参数
viewRFC 1123 格式字符串
返回
是否解析成功

在文件 datetime.hpp1360 行定义.

引用了 parse_RFC1123() , 以及 swap().

◆ try_parse_RFC3339()

bool datetime::try_parse_RFC3339 ( const string_view view)
inlineconstexprnoexcept

尝试解析 RFC 3339

参数
viewRFC 3339 格式字符串
返回
是否解析成功

在文件 datetime.hpp1281 行定义.

引用了 parse_RFC3339() , 以及 swap().

被这些函数引用 toml_datetime::toml_datetime() , 以及 yaml_timestamp::yaml_timestamp().

◆ year()

date_type datetime::year ( ) const
inlinenodiscardconstexprnoexcept

获取年份

返回
年份

在文件 datetime.hpp965 行定义.

被这些函数引用 datetime(), datetime() , 以及 parse_RFC1123().


该类的文档由以下文件生成: