/
wxString_GetTime_GetNow.cpp
64 lines (52 loc) · 1.53 KB
/
wxString_GetTime_GetNow.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
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
#include <wx/wx.h>
#include <string>
#include <sstream>
#include <iostream>
#include <map>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
using namespace std;
//处理2012-5-18 14:59:22 这样的时间字符串, 来自于 还原点配置文件.
long GetTime( wxString strTime )
{
long lTime = 0 ;
long lYear = 0 ;
long lMonth = 0 ;
long lDay = 0 ;
long lHour = 0 ;
long lMinute = 0 ;
long lSecond = 0 ;
wxString strYear = strTime.BeforeFirst( _T('-') ) ;
strYear.ToLong( &lYear ) ;
wxString strMonth = strTime.AfterFirst( _T('-') ) ;
strMonth = strMonth.BeforeFirst( _T('-') ) ;
strMonth.ToLong( &lMonth ) ;
wxString strDay = strTime.BeforeFirst( _T(' ') ) ;
strDay = strDay.AfterLast( _T('-') ) ;
strDay.ToLong( &lDay ) ;
wxString strHour = strTime.AfterFirst( _T(' ') ) ;
strHour = strHour.BeforeFirst( _T(':') ) ;
strHour.ToLong( &lHour ) ;
wxString strMinute = strTime.BeforeLast( _T(':') ) ;
strMinute = strMinute.AfterLast( _T(':') ) ;
strMinute.ToLong( &lMinute ) ;
wxString strSecond = strTime.AfterLast( _T(':') ) ;
strSecond.ToLong( &lSecond ) ;
wxDateTime Date( lDay, (wxDateTime::Month)(lMonth - 1), lYear, lHour, lMinute, lSecond ) ;
lTime = Date.GetTicks() ;
return lTime ;
}
int main()
{
wxString time_str=_T("2012-5-18 14:59:22");
string stl_str(time_str.mb_str());
long tmp= GetTime(time_str);
printf("%ld\n", tmp);
printf("%s\n", stl_str.c_str());
char buffer[128]={0};
time_t t=tmp;
//t=time(NULL);
strftime(buffer, sizeof(buffer), "%Y_%m_%d_%T\n", localtime(&t));
printf("%s", buffer);
}