| 1 |
sysadm |
1.1 |
/*******************************************************/
|
| 2 |
|
|
/* */
|
| 3 |
sysadm |
1.2 |
/* LeafOK Innbbsd */
|
| 4 |
sysadm |
1.1 |
/* Copyright (C) LeafOK.com, 2003-2004 */
|
| 5 |
|
|
/* */
|
| 6 |
|
|
/* Programmed by Leaf */
|
| 7 |
sysadm |
1.2 |
/* E-mail:leaflet@leafok.com QQ:6049044 */
|
| 8 |
sysadm |
1.1 |
/* */
|
| 9 |
|
|
/* http://bbs.leafok.com */
|
| 10 |
|
|
/* http://bbs.leafok.net */
|
| 11 |
|
|
/* http://bbs.fenglin.info */
|
| 12 |
|
|
/* */
|
| 13 |
|
|
/*******************************************************/
|
| 14 |
|
|
|
| 15 |
|
|
#include "StdAfx.h"
|
| 16 |
|
|
#include ".\datetimeconvert.h"
|
| 17 |
|
|
|
| 18 |
|
|
DateTimeConvert::DateTimeConvert(const char* str_time)
|
| 19 |
|
|
{
|
| 20 |
|
|
if (str_time)
|
| 21 |
|
|
this->strtotime(str_time);
|
| 22 |
|
|
}
|
| 23 |
|
|
|
| 24 |
|
|
DateTimeConvert::~DateTimeConvert(void)
|
| 25 |
|
|
{
|
| 26 |
|
|
}
|
| 27 |
|
|
|
| 28 |
|
|
int DateTimeConvert::strtotime(const char* str_time)
|
| 29 |
|
|
{
|
| 30 |
|
|
char month[4],temp[80];
|
| 31 |
|
|
// Wed, 30 Jul 2003 14:39:31 GMT
|
| 32 |
|
|
|
| 33 |
|
|
sscanf(str_time,"%s",temp);
|
| 34 |
|
|
if (temp[strlen(temp)-1] == ',')
|
| 35 |
|
|
{
|
| 36 |
|
|
sscanf(str_time,"%*s %d %s %d %d:%d:%d",
|
| 37 |
|
|
&(this->time.tm_mday),month,&(this->time.tm_year),
|
| 38 |
|
|
&(this->time.tm_hour),&(this->time.tm_min),&(this->time.tm_sec));
|
| 39 |
|
|
}
|
| 40 |
|
|
else
|
| 41 |
|
|
{
|
| 42 |
|
|
sscanf(str_time,"%d %s %d %d:%d:%d",
|
| 43 |
|
|
&(this->time.tm_mday),month,&(this->time.tm_year),
|
| 44 |
|
|
&(this->time.tm_hour),&(this->time.tm_min),&(this->time.tm_sec));
|
| 45 |
|
|
}
|
| 46 |
|
|
|
| 47 |
|
|
if (strcmp(month,"Jan") == 0)
|
| 48 |
|
|
this->time.tm_mon = 1;
|
| 49 |
|
|
if (strcmp(month,"Feb") == 0)
|
| 50 |
|
|
this->time.tm_mon = 2;
|
| 51 |
|
|
if (strcmp(month,"Mar") == 0)
|
| 52 |
|
|
this->time.tm_mon = 3;
|
| 53 |
|
|
if (strcmp(month,"Apr") == 0)
|
| 54 |
|
|
this->time.tm_mon = 4;
|
| 55 |
|
|
if (strcmp(month,"May") == 0)
|
| 56 |
|
|
this->time.tm_mon = 5;
|
| 57 |
|
|
if (strcmp(month,"Jun") == 0)
|
| 58 |
|
|
this->time.tm_mon = 6;
|
| 59 |
|
|
if (strcmp(month,"Jul") == 0)
|
| 60 |
|
|
this->time.tm_mon = 7;
|
| 61 |
|
|
if (strcmp(month,"Aug") == 0)
|
| 62 |
|
|
this->time.tm_mon = 8;
|
| 63 |
|
|
if (strcmp(month,"Sep") == 0)
|
| 64 |
|
|
this->time.tm_mon = 9;
|
| 65 |
|
|
if (strcmp(month,"Oct") == 0)
|
| 66 |
|
|
this->time.tm_mon = 10;
|
| 67 |
|
|
if (strcmp(month,"Nov") == 0)
|
| 68 |
|
|
this->time.tm_mon = 11;
|
| 69 |
|
|
if (strcmp(month,"Dec") == 0)
|
| 70 |
|
|
this->time.tm_mon = 12;
|
| 71 |
|
|
|
| 72 |
|
|
return 0;
|
| 73 |
|
|
}
|
| 74 |
|
|
|
| 75 |
|
|
CString DateTimeConvert::strftime(void) const
|
| 76 |
|
|
{
|
| 77 |
|
|
//%y-%m-%d %H:%M:%S
|
| 78 |
|
|
CString str;
|
| 79 |
|
|
|
| 80 |
|
|
str.Format("%d-%d-%d %.2d:%.2d:%.2d",
|
| 81 |
|
|
this->time.tm_year,this->time.tm_mon,this->time.tm_mday,
|
| 82 |
|
|
this->time.tm_hour,this->time.tm_min,this->time.tm_sec);
|
| 83 |
|
|
|
| 84 |
|
|
return str;
|
| 85 |
|
|
}
|
| 86 |
|
|
|
| 87 |
|
|
time_t DateTimeConvert::mktime(void)
|
| 88 |
|
|
{
|
| 89 |
|
|
return ::mktime(&(this->time));
|
| 90 |
|
|
}
|
| 91 |
|
|
|
| 92 |
|
|
__time64_t DateTimeConvert::_mktime64(void)
|
| 93 |
|
|
{
|
| 94 |
|
|
return ::_mktime64(&(this->time));
|
| 95 |
|
|
}
|
| 96 |
|
|
|
| 97 |
|
|
COleDateTime DateTimeConvert::ToOleDataTime(void) const
|
| 98 |
|
|
{
|
| 99 |
|
|
return COleDateTime(this->time.tm_year,this->time.tm_mon,this->time.tm_mday,
|
| 100 |
|
|
this->time.tm_hour,this->time.tm_min,this->time.tm_sec);
|
| 101 |
|
|
}
|
| 102 |
|
|
|
| 103 |
|
|
DateTimeConvert::DateTimeConvert(TIMESTAMP_STRUCT* timestamp)
|
| 104 |
|
|
{
|
| 105 |
|
|
this->time.tm_year = timestamp->year;
|
| 106 |
|
|
this->time.tm_mon = timestamp->month;
|
| 107 |
|
|
this->time.tm_mday = timestamp->day;
|
| 108 |
|
|
this->time.tm_hour = timestamp->hour;
|
| 109 |
|
|
this->time.tm_min = timestamp->minute;
|
| 110 |
|
|
this->time.tm_sec = timestamp->day;
|
| 111 |
|
|
}
|
| 112 |
|
|
|
| 113 |
|
|
CString DateTimeConvert::gmstrftime(void) const
|
| 114 |
|
|
{
|
| 115 |
|
|
//"%d %b %Y %H:%M:%S GMT"
|
| 116 |
|
|
CString str,month;
|
| 117 |
|
|
|
| 118 |
|
|
switch(this->time.tm_mon)
|
| 119 |
|
|
{
|
| 120 |
|
|
case 1:
|
| 121 |
|
|
month="Jan";
|
| 122 |
|
|
break;
|
| 123 |
|
|
case 2:
|
| 124 |
|
|
month="Feb";
|
| 125 |
|
|
break;
|
| 126 |
|
|
case 3:
|
| 127 |
|
|
month="Mar";
|
| 128 |
|
|
break;
|
| 129 |
|
|
case 4:
|
| 130 |
|
|
month="Apr";
|
| 131 |
|
|
break;
|
| 132 |
|
|
case 5:
|
| 133 |
|
|
month="May";
|
| 134 |
|
|
break;
|
| 135 |
|
|
case 6:
|
| 136 |
|
|
month="Jun";
|
| 137 |
|
|
break;
|
| 138 |
|
|
case 7:
|
| 139 |
|
|
month="Jul";
|
| 140 |
|
|
break;
|
| 141 |
|
|
case 8:
|
| 142 |
|
|
month="Aug";
|
| 143 |
|
|
break;
|
| 144 |
|
|
case 9:
|
| 145 |
|
|
month="Sep";
|
| 146 |
|
|
break;
|
| 147 |
|
|
case 10:
|
| 148 |
|
|
month="Oct";
|
| 149 |
|
|
break;
|
| 150 |
|
|
case 11:
|
| 151 |
|
|
month="Nov";
|
| 152 |
|
|
break;
|
| 153 |
|
|
case 12:
|
| 154 |
|
|
month="Dec";
|
| 155 |
|
|
break;
|
| 156 |
|
|
default:
|
| 157 |
|
|
month="Jan";
|
| 158 |
|
|
}
|
| 159 |
|
|
|
| 160 |
|
|
str.Format("%d %s %d %.2d:%.2d:%.2d GMT",
|
| 161 |
|
|
this->time.tm_mday,month,this->time.tm_year,
|
| 162 |
|
|
this->time.tm_hour,this->time.tm_min,this->time.tm_sec);
|
| 163 |
|
|
|
| 164 |
|
|
return str;
|
| 165 |
|
|
}
|