Cross-platform date and time manipulation utilities.
- Current date/time retrieval
- Custom formatting (strftime compatible)
- Time storage and manipulation
- Comparison operators
Windows/Linux/macOSsupport
DateTime()- Constructor with current system timeDateTime(time_t time_a)- Constructor with custom timestd::string GetCurrentDateTime() const- Returns "YYYY-MM-DD HH:MM:SS"std::string GetCurrentDate() const- Returns "YYYY-MM-DD"std::string GetCurrentTime() const- Returns "HH:MM:SS"std::string Format(const std::string& format_a) const- Custom time formattingvoid SetTime(time_t time_a)- Set custom time valuetime_t GetTime() const- Get raw time value- Comparison operators (
==,!=,<,>,<=,>=)
#include <CUtils/DateTime.hpp>
int main()
{
// Create with current time
CUtils::DateTime now_;
// Format examples
std::cout << "Full datetime: " << now_.GetCurrentDateTime() << std::endl;
std::cout << "Custom format: " << now_.Format("%A, %B %d") << std::endl;
// Time manipulation
time_t yesterday_ = now_.GetTime() - 86400; // 86400 seconds = 1 day
CUtils::DateTime past_(yesterday_);
// Comparison
if (past_ < now_)
{
std::cout << "Yesterday was earlier than today" << std::endl;
}
return 0;
}Кросс-платформенные утилиты для работы с датой и временем.
- Получение текущей даты/времени
- Произвольное форматирование (совместимо с strftime)
- Хранение и манипуляция временем
- Операторы сравнения
- Поддержка
Windows/Linux/macOS
DateTime()- Конструктор с текущим системным временемDateTime(time_t time_a)- Конструктор с пользовательским временемstd::string GetCurrentDateTime() const- Возвращает "ГГГГ-ММ-ДД ЧЧ:ММ:СС"std::string GetCurrentDate() const- Возвращает "ГГГГ-ММ-ДД"std::string GetCurrentTime() const- Возвращает "ЧЧ:ММ:СС"std::string Format(const std::string& format_a) const- Произвольное форматированиеvoid SetTime(time_t time_a)- Установка пользовательского времениtime_t GetTime() const- Получение времени в сыром виде- Операторы сравнения
(==, !=, <, >, <=, >=)
#include <CUtils/DateTime.hpp>
int main()
{
// Создавать с учетом текущего времени
CUtils::DateTime now_;
// Примеры форматирования
std::cout << "Полная дата и время: " << now_.GetCurrentDateTime() << std::endl;
std::cout << "Пользовательский формат: " << now_.Format("%A, %B %d") << std::endl;
// Манипулирование временем
time_t yesterday_ = now_.GetTime() - 86400; // 86400 секунд = 1 день
CUtils::DateTime past_(yesterday_);
// Сравнение
if (past_ < now_)
{
std::cout << "Вчера было раньше, чем сегодня" << std::endl;
}
return 0;
}