forked from calccrypto/OpenPGP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpgptime.cpp
25 lines (22 loc) · 824 Bytes
/
pgptime.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "pgptime.h"
// get current time since epoch
time_t now(){
time_t rawtime;
time(&rawtime);
return rawtime;
}
// write a time in seconds from epoch to string
std::string show_time(time_t T){
// value to string conversion
struct tm * gmt = gmtime(&T);
std::stringstream date;
// convert to string. could use asctime, but needed a bit more info
date << dayofweek[gmt -> tm_wday] << " " << month[gmt -> tm_mon] << " " << gmt -> tm_mday << " " << gmt -> tm_hour << ":" << gmt -> tm_min << ":" << gmt -> tm_sec << " UTC " << (1900 + gmt -> tm_year);
return date.str();
}
std::string show_date(time_t T){
struct tm * gmt = gmtime(&T);
std::stringstream date;
date << (1900 + gmt -> tm_year) << "-" << (gmt -> tm_mon + 1) << "-" << gmt -> tm_mday;
return date.str();
}