当前位置: 技术问答>linux和unix
各位可否给个用C获得时间并格式化输出的例子
来源: 互联网 发布时间:2015-05-31
本文导语: 同标题,顶有分 | #include #include typedef struct tabDATETIME { unsigned short year; unsigned short month; unsigned short day; unsigned short hour; unsigned short minute; unsigned short second; unsigned short milisecon...
同标题,顶有分
|
#include
#include
typedef struct tabDATETIME
{
unsigned short year;
unsigned short month;
unsigned short day;
unsigned short hour;
unsigned short minute;
unsigned short second;
unsigned short milisecond;
}DATATIME,*LPDATETIME;
int getDATETIME(LPDATETIME pdt)
{
struct timeb tb;
struct time *ptm;
ftime(&tb);
ptm=localtime((time_t*)&tb.time);
pdt->year=ptm->tm_year+1900;
pdt->month=ptm->tm_month+1;
pdt->day=ptm->tm_mday;
pdt->hour=ptm->tm_hour;
pdt->minute=ptm->tm_min;
pdt->seconds=ptm->tm_sec;
pdt->milliseconds=tb.millitm;
return 0;
}
#include
typedef struct tabDATETIME
{
unsigned short year;
unsigned short month;
unsigned short day;
unsigned short hour;
unsigned short minute;
unsigned short second;
unsigned short milisecond;
}DATATIME,*LPDATETIME;
int getDATETIME(LPDATETIME pdt)
{
struct timeb tb;
struct time *ptm;
ftime(&tb);
ptm=localtime((time_t*)&tb.time);
pdt->year=ptm->tm_year+1900;
pdt->month=ptm->tm_month+1;
pdt->day=ptm->tm_mday;
pdt->hour=ptm->tm_hour;
pdt->minute=ptm->tm_min;
pdt->seconds=ptm->tm_sec;
pdt->milliseconds=tb.millitm;
return 0;
}
|
自己man一下strftime
|
我想自己用snprintf也不复杂吧。
|
man ctime