Menu

[r3]: / time.cpp  Maximize  Restore  History

Download this file

44 lines (38 with data), 931 Bytes

 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "time.hpp"
#include <stdio.h>
using namespace std;
time_t current_time;
string current_time_name;
string time_to_name(time_t *t)
{
struct tm *timeinfo;
char name[80];
timeinfo = localtime(t);
sprintf(name, "%04d-%02d-%02d_%02d.%02d.%02d",
timeinfo->tm_year + 1900,
timeinfo->tm_mon + 1,
timeinfo->tm_mday,
timeinfo->tm_hour,
timeinfo->tm_min,
timeinfo->tm_sec);
return string(name);
}
string time_to_touch(time_t *t)
{
struct tm *timeinfo;
char name[80];
timeinfo = localtime(t);
sprintf(name, "%04d%02d%02d%02d%02d.%02d",
timeinfo->tm_year + 1900,
timeinfo->tm_mon + 1,
timeinfo->tm_mday,
timeinfo->tm_hour,
timeinfo->tm_min,
timeinfo->tm_sec);
return string(name);
}
void compute_current_time()
{
time(&current_time);
current_time_name = time_to_name(&current_time);
}
MongoDB Logo MongoDB