1 |
bearsoft |
1.1 |
#include "DateTime.h"
|
2 |
|
|
#include <time.h>
|
3 |
|
|
#include "../System/SystemDefine.h"
|
4 |
|
|
#include "../String/StringTools.h"
|
5 |
|
|
|
6 |
|
|
DateTime::DateTime(int iOption)
|
7 |
|
|
{
|
8 |
|
|
buffer=get(iOption);
|
9 |
|
|
}
|
10 |
|
|
|
11 |
|
|
DateTime::DateTime(int iOption, long t)
|
12 |
|
|
{
|
13 |
|
|
buffer=get(iOption, t);
|
14 |
|
|
}
|
15 |
|
|
|
16 |
|
|
DateTime::~DateTime(){}
|
17 |
|
|
|
18 |
|
|
char *DateTime::get(int option)
|
19 |
|
|
{
|
20 |
|
|
return get(option, time(NULL));
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
char *DateTime::get(int option, long t)
|
24 |
|
|
{
|
25 |
|
|
StringTools stringTools;
|
26 |
|
|
|
27 |
|
|
char *curTime = (char*)malloc(66*sizeof(char));
|
28 |
|
|
|
29 |
|
|
if ( option == 0 )
|
30 |
|
|
{
|
31 |
|
|
if (strftime(curTime,64,"%Y-%m-%d",localtime(&t))!=0)
|
32 |
|
|
{
|
33 |
|
|
length=stringTools.sizeOfStringWithOutEndNull(curTime);
|
34 |
|
|
return curTime;
|
35 |
|
|
}
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
if ( option == 1 )
|
39 |
|
|
{
|
40 |
|
|
if (strftime(curTime,64,"%H.%M",localtime(&t))!=0)
|
41 |
|
|
{
|
42 |
|
|
length=stringTools.sizeOfStringWithOutEndNull(curTime);
|
43 |
|
|
return curTime;
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
if ( option == 2 )
|
49 |
|
|
{
|
50 |
|
|
if (strftime(curTime,64,"%Y-%m-%d:%H.%M",localtime(&t))!=0)
|
51 |
|
|
{
|
52 |
|
|
length=stringTools.sizeOfStringWithOutEndNull(curTime);
|
53 |
|
|
return curTime;
|
54 |
|
|
}
|
55 |
|
|
}
|
56 |
|
|
/*
|
57 |
|
|
|
58 |
|
|
curTime[0]='1';
|
59 |
|
|
curTime[1]=0;
|
60 |
|
|
length=1;
|
61 |
|
|
return curTime;
|
62 |
|
|
*/
|
63 |
|
|
|
64 |
|
|
if (curTime!=null)
|
65 |
|
|
{
|
66 |
|
|
free(curTime);
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
return null;
|
70 |
|
|
} |