各位可否给个用C获得时间并格式化输出的例子

lovered 2004-01-09 06:12:38
同标题,顶有分
...全文
76 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ks9960 2004-01-10
  • 打赏
  • 举报
回复
自己man一下strftime
softwarrior 2004-01-10
  • 打赏
  • 举报
回复
man ctime
rexp 2004-01-10
  • 打赏
  • 举报
回复
我想自己用snprintf也不复杂吧。
slippercat 2004-01-09
  • 打赏
  • 举报
回复
#include <time.h>
#include <sys/timeb.h>
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;

}

23,120

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧