-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimestamp.c
114 lines (97 loc) · 3.12 KB
/
Timestamp.c
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
////////////////////////////////////////////////////////////////////////////////
//
// Global including files.
//
// Including the files for the system.
//
// These including files are generally used in different operation system.
//
////////////////////////////////////////////////////////////////////////////////
#include "Global.h"
////////////////////////////////////////////////////////////////////////////////
//
// Get timestamp comment.
//
////////////////////////////////////////////////////////////////////////////////
void GetTimestampComment(_PASCALSTRING strTimestamp,_UINT32 nTimestamp)
{
//Timestamp is MMDDHHMMSS in DEC.
_UINT32 nMonth,nDay,nHour,nMinute,nSecond;
//Get month.
nMonth = nTimestamp / 100000000;
nTimestamp = nTimestamp % 100000000;
//Get day.
nDay = nTimestamp / 1000000;
nTimestamp = nTimestamp % 1000000;
//Get hour.
nHour = nTimestamp / 10000;
nTimestamp = nTimestamp % 10000;
//Get minute.
nMinute = nTimestamp / 100;
//Get second.
nSecond = nTimestamp % 100;
//Convert into string.
sprintf(strTimestamp,"%02d-%02d %02d:%02d:%02d",
nMonth,nDay,nHour,nMinute,nSecond);
}
////////////////////////////////////////////////////////////////////////////////
//
// Format timestamp.
//
////////////////////////////////////////////////////////////////////////////////
void FormatTimestamp(_PASCALSTRING strTimestamp,_UINT32 nTimestamp)
{
//Timestamp is MMDDHHMMSS in DEC.
_UINT32 nMonth,nDay,nHour,nMinute,nSecond;
//Get month.
nMonth = nTimestamp / 100000000;
nTimestamp = nTimestamp % 100000000;
//Get day.
nDay = nTimestamp / 1000000;
nTimestamp = nTimestamp % 1000000;
//Get hour.
nHour = nTimestamp / 10000;
nTimestamp = nTimestamp % 10000;
//Get minute.
nMinute = nTimestamp / 100;
//Get second.
nSecond = nTimestamp % 100;
//Convert into string.
sprintf(strTimestamp,"%02d%02d%02d%02d%02d",
nMonth,nDay,nHour,nMinute,nSecond);
}
////////////////////////////////////////////////////////////////////////////////
//
// Scan timestamp.
//
////////////////////////////////////////////////////////////////////////////////
void ScanTimestamp(_PASCALSTRING strTimestamp,_UINT32* lpTimestamp)
{
//Timestamp is MMDDHHMMSS in DEC.
int nMonth = 0,nDay = 0,nHour = 0,nMinute = 0,nSecond = 0;
//Scan month, day, hour, minute and second.
sscanf(strTimestamp,"%02d%02d%02d%02d%02d",
&nMonth,&nDay,&nHour,&nMinute,&nSecond);
*lpTimestamp = nMonth * 100000000 +
nDay * 1000000 + nHour * 10000 + nMinute * 100 + nSecond;
}
////////////////////////////////////////////////////////////////////////////////
//
// Get current timestamp comment.
//
////////////////////////////////////////////////////////////////////////////////
_UINT32 GetCurrentTimestamp()
{
SimpleTime timeCurrent;
_PASCALSTRING strTimeCompactFormat;
_UINT32 nTimestamp = 0;
//Initialize current time.
InitializeTime(&timeCurrent);
//Get rid of the year.
sprintf(strTimeCompactFormat,"%02d%02d%02d%02d%02d",
timeCurrent.nDateValues[1],timeCurrent.nDateValues[2],
timeCurrent.nTimeValues[0],timeCurrent.nTimeValues[1],timeCurrent.nTimeValues[2]);
//Scan timestamp.
ScanTimestamp(strTimeCompactFormat,&nTimestamp);
return nTimestamp;
}