获取系统日期

来源:互联网 发布:淘宝导航css代码模板 编辑:程序博客网 时间:2024/06/05 23:52
/* get the local system date */int get_system_date(char *str_date){    struct tm *tp=NULL;    time_t t;    time(&t);    tp = (struct tm *)localtime(&t);    sprintf(str_date, "%04d%02d%02d", tp->tm_year+1900,tp->tm_mon+1,tp->tm_mday);    return 0;}


/*附另一参考函数*/int GetSysDateTime(char *DateStr){    struct tm     *tp=NULL;    time_t t;    time(&t);    tp = (struct tm *)localtime(&t);    sprintf(DateStr,"%04d%02d%02d%02d%02d%02d",     tp->tm_year+1900,tp->tm_mon+1,tp->tm_mday,tp->tm_hour,tp->tm_min,tp->tm_sec);    return(0);}