Version 2.0 of the original datetime lib from pcannon09!
- Include:
#include "dt.hpp"- Get version:
Definition in hpp file:
extern std::string version;How to get version
std::string datetimeVersion = dt::version;- Get current time Definition of sysClock type in hpp file
typedef std::chrono::time_point<std::chrono::system_clock> sysClock;Definition in hpp file:
sysClock get();How to get current time
sysClock timeNow = dt::get();- Set 24h or 12h clock Definition in hpp file:
bool set24h(bool x);How to set 12h or 24h:
// This code will set the hour format to 12h
// There is an optional variable to save the value of the 'set24h' function that was called
bool optionalVariable = set24h(false);
// This code will set the hout format to 24h
bool optionalVariable = set24h(true);- How to get if it's Am or Pm Definition in hpp file:
std::string amOrPm(sysClock timeNow);How to use it:
// This will return Am or Pm
std::string returnValue = amOrPm(timeNow);- How to get time info Definitions in hpp file:
int sec(sysClock timeNow); // Get second
int hr(sysClock timeNow); // Get hour
int min(); // Get min
int ms(sysClock timeNow); // Get millisecond
int us(sysClock timeNow); // Get microsecondGet time info:
int hourVar = dt::hr(timeNow); // This can get the current hour (You can use 'dt::hour()' aswell)
int minVar = dt::min(timeNow); // This can get the current minute (You can use 'dt::minute()' aswell)
int secVar = dt::sec(timeNow); // This can get the current second (You can use 'dt::second()' aswell)
int msVar = dt::ms(timeNow); // This can get the current millisecond (You can use 'dt::millisecond' aswell)
int usVar = dt::us(timeNow); // This can get the current microsecond (You can use 'dt::microsecond' aswell)- Get date info Definitions in hpp file
int year(); // Get current year
int wday(); // Get day of the week
int day(); // Get day
int month(); // Get month
int yday(); // Get day of the year
int isdst(); // Get DST
std::string timezone(); // Get current timezoneGet date info:
int dayVar = dt::day(); // Get current day
int monthVar = dt::month(); // Get current month
int yearVar = dt::year(); // Get current year
int weekDayVar = dt::wday(); // Get week day
int yearDayVar = dt::yday(); // Get year day
int isdstVar = dt::isdst(); // Get DST
std::string zoneVar = dt::timezone();