typedef struct
{
int wSecond;
/* Seconds.
[0-60] (1 leap second) */
int wMinute;
/* Minutes.
[0-59] */
int wHour;
/* Hours.
[0-23] */
int wDay;
/* Day.
[1-31] */
int wMonth;
/* Month.
[0-11] */
int wYear;
/* Year
- 1900. */
int wDayOfWeek;
/* Day of week.
[0-6] */
int tm_yday;
/* Days in year.[0-365]
*/
int tm_isdst;
/* DST.
[-1/0/1]*/
#ifdef
__USE_BSD
long int tm_gmtoff;
/* Seconds east of UTC. */
__const char *tm_zone;
/* Timezone abbreviation. */
#else
long int __tm_gmtoff;
/* Seconds east of UTC. */
__const char *__tm_zone;
/* Timezone abbreviation. */
#endif
}SYSTEMTIME;
void GetLocalTime(SYSTEMTIME *st)
{
if(st)
{
struct tm *pst = NULL;
time_t t = time(NULL);
pst = localtime(&t);
memcpy(st,pst,sizeof(SYSTEMTIME));
st->wYear += 1900;
}
}
#include <time.h>
int main()
{
char buf[32] = {0};
struct tm* ptm = NULL;
time_t t = time(NULL);
ptm = localtime(&t);
strftime(buf,sizeof(buf),"%Y-%m-%d %H:%M:%S",ptm);
cout<<buf<<endl;
return -1;
}
/*
%y Year without century, as a decimal number (00-99).
%Y Year with century, as a decimal number.
%m Month as a decimal number (01-12).
%M Minute as a decimal number (00-59).
%d Day of the month as a decimal number (01-31).
%H Hour (24-hour clock) as a decimal number (00-23).
%S Second as a decimal number (00-59).
*/