33 lines
813 B
C++
33 lines
813 B
C++
f64 microtime()
|
|
{
|
|
return ((f64)std::chrono::duration_cast<std::chrono::microseconds>(
|
|
std::chrono::high_resolution_clock::now().time_since_epoch()).count()) / 1000000;
|
|
}
|
|
|
|
u64 time()
|
|
{
|
|
return(std::time(0));
|
|
}
|
|
|
|
string date(string format = "", u64 timestamp = 0)
|
|
{
|
|
string ts;
|
|
string fmt;
|
|
if(timestamp > 0) ts = string("-d '@")+to_string(timestamp)+"'";
|
|
if(format != "") fmt = string("+'"+format+"'");
|
|
return(trim(shell_exec("date "+ts+" "+fmt)));
|
|
}
|
|
|
|
string gmdate(string format = "", u64 timestamp = 0)
|
|
{
|
|
string ts;
|
|
string fmt;
|
|
if(timestamp > 0) ts = string("'@")+to_string(timestamp)+"'";
|
|
if(format != "") fmt = string("+'"+format+"'");
|
|
return(trim(shell_exec("date -u "+ts+" "+fmt)));
|
|
}
|
|
|
|
u64 parse_time(string time_string)
|
|
{
|
|
return(int_val(trim(shell_exec("date -u -d '"+time_string+"' +'%s'"))));
|
|
} |