ngl_server 1.0
基于 Actor 模型的 C++ 服务器框架
tools_time.h File Reference

时间工具:纪元转换、格式化时间戳、星期/日期边界辅助函数。 More...

#include <cstdio>
#include <string>
#include <ctime>

Namespaces

namespace  ngl::tools
 工具函数命名空间。
namespace  ngl::tools::time
 时间工具命名空间,提供时间相关的工具函数。

Enumerations

enum  {
  MILLISECOND = 1000 , MINUTES_SECOND = 1 * 60 , MINUTES_MILLISECOND = MINUTES_SECOND * MILLISECOND , HOUR_MINUTES = 1 * 60 ,
  HOUR_SECOND = MINUTES_SECOND * HOUR_MINUTES , HOUR_MILLISECOND = HOUR_SECOND * MILLISECOND , DAY_HOUR = 24 , DAY_MINUTES = DAY_HOUR * HOUR_MINUTES ,
  DAY_SECOND = DAY_HOUR * HOUR_SECOND , DAY_MILLISECOND = DAY_SECOND * MILLISECOND , WEEK_DAY = 7 , WEEK_HOUR = WEEK_DAY * DAY_HOUR ,
  WEEK_MINUTES = WEEK_DAY * DAY_MINUTES , WEEK_SECOND = WEEK_DAY * DAY_SECOND , WEEK_MILLISECOND = WEEK_SECOND * MILLISECOND
}
 时间单位常量定义。 More...

Functions

bool ngl::tools::time::check_month (int amonth)
 检查月份是否有效
bool ngl::tools::time::check_monthday (int amonthday)
 检查日是否有效
bool ngl::tools::time::check_week (int aweek)
 检查星期是否有效
bool ngl::tools::time::check_hour (int hour)
 检查小时是否有效
bool ngl::tools::time::check_minute (int minute)
 检查分钟是否有效
bool ngl::tools::time::check_sec (int sec)
 检查秒是否有效
bool ngl::tools::time::timeout (time_t abeg, int32_t atimeoutms)
 检查是否超时
bool ngl::tools::time::settime (time_t sti)
 设置模拟时间
time_t ngl::tools::time::gettime ()
 获取当前时间(带偏移)
time_t ngl::tools::time::getsystime ()
 获取系统真实时间(不带偏移)
time_t ngl::tools::time::getms ()
 获取当前毫秒数(仅亚秒部分)
time_t ngl::tools::time::gettimems ()
 获取当前时间戳(毫秒)
bool ngl::tools::time::issameday (time_t a1, time_t a2)
 判断两个时间戳是否在同一天
bool ngl::tools::time::issameday (time_t autc)
 判断时间戳是否与当前时间在同一天
void ngl::tools::time::printf_time2str (time_t anow, const char *format)
 打印格式化时间字符串到标准输出
size_t ngl::tools::time::time2str (char *str, int len, time_t anow, const char *format)
 将时间戳格式化为字符串
std::string ngl::tools::time::time2str (time_t anow, const char *format)
 将时间戳格式化为std::string
std::string ngl::tools::time::time2str (const char *format)
 将当前时间格式化为字符串
time_t ngl::tools::time::str2time (const char *astr, const char *format)
 将时间字符串解析为时间戳
time_t ngl::tools::time::getsecond2time (time_t utc, int hour, int minute, int sec)
 获取指定时间当天的指定时刻
time_t ngl::tools::time::getsecond2time (int hour, int minute, int sec)
 获取今天或明天的指定时刻
time_t ngl::tools::time::getsecond2time (int minute, int sec)
 获取当前小时或下一小时的指定时刻
time_t ngl::tools::time::getsecond2time (int sec)
 获取当前分钟或下一分钟的指定时刻
time_t ngl::tools::time::getweekday (time_t utc, int aweek, int hour, int minute, int sec)
 获取指定星期几的指定时刻
time_t ngl::tools::time::getweekday (int aweek, int hour, int minute, int sec)
 获取本周指定星期几的指定时刻
bool ngl::tools::time::isleapyear (int year)
 判断是否为闰年
bool ngl::tools::time::monthday (int year, int month, int aday)
 检查指定年月日是否有效
std::pair< bool, time_t > ngl::tools::time::getmonthday (time_t utc, int amday, int hour, int minute, int sec)
 获取本月指定日的指定时刻
std::pair< bool, time_t > ngl::tools::time::getmonthday (int amday, int hour, int minute, int sec)
 获取本月指定日的指定时刻(使用当前时间)
time_t ngl::tools::time::getspandays (time_t curr, time_t last)
 计算两个时间戳之间的天数差
int ngl::tools::time::getday (const tm *atm)
 从tm结构获取日
int ngl::tools::time::getday (time_t curr)
 获取时间戳的日
int ngl::tools::time::getday ()
 获取当前日
int ngl::tools::time::getmonth (const tm *atm)
 从tm结构获取月份
int ngl::tools::time::getmonth (time_t curr)
 获取时间戳的月份
int ngl::tools::time::getmonth ()
 获取当前月份
int ngl::tools::time::getyear (const tm *atm)
 从tm结构获取年份
int ngl::tools::time::getyear (time_t curr)
 获取时间戳的年份
int ngl::tools::time::getyear ()
 获取当前年份
int ngl::tools::time::getweekday (const tm *atm)
 从tm结构获取星期几
int ngl::tools::time::getweekday (time_t curr)
 获取时间戳的星期几
int ngl::tools::time::getweekday ()
 获取当前星期几
int ngl::tools::time::gethour (const tm *atm)
 从tm结构获取小时
int ngl::tools::time::gethour (time_t curr)
 获取时间戳的小时
int ngl::tools::time::gethour ()
 获取当前小时
int ngl::tools::time::getmin (const tm *atm)
 从tm结构获取分钟
int ngl::tools::time::getmin (time_t curr)
 获取时间戳的分钟
int ngl::tools::time::getmin ()
 获取当前分钟
int ngl::tools::time::getsec (const tm *atm)
 从tm结构获取秒
int ngl::tools::time::getsec (time_t curr)
 获取时间戳的秒
int ngl::tools::time::getsec ()
 获取当前秒
void ngl::tools::time::getweekday (time_t curr, int &weekday, int &hour, int &minute)
 获取时间戳的星期、小时和分钟
void ngl::tools::time::gettm (time_t curr, tm &atm)
 将时间戳转换为tm结构
int ngl::tools::time::getutcbyhour (time_t utc, int hour)
 获取指定小时数后的整点时间
int ngl::tools::time::getutcbymin (time_t utc, int amin)
 获取指定分钟数后的整分时间
bool ngl::tools::time::checkutc (time_t autc1, time_t autc2)
 检查第一个时间戳是否晚于第二个
bool ngl::tools::time::checkutc (time_t autc)
 检查时间戳是否晚于当前时间
bool ngl::tools::time::issameweek (time_t timestamp1, time_t timestamp2)
 判断两个时间戳是否在同一周
void ngl::tools::time::test_isweek ()
 测试issameweek函数

Detailed Description

时间工具:纪元转换、格式化时间戳、星期/日期边界辅助函数。

提供全面的时间处理功能,包括时间单位转换、日历组件提取、 时间格式化和解析、日期比较和边界计算。支持逻辑服务器时间同步。