- 论坛徽章:
- 1
|
我们在用的代码,应该是你要的
- #include <time.h>
- #include <sys/time.h>
- /**
- * get the local date or time in specified time zone for the specified UTC timestamp.
- * you can pass NULL for pointer-typed parameters.
- * return 0 on sucess, return -1 if error occured.
- * @year will be the A.D number, @month will be 1~12, @mday will be 1~31
- */
- int util_time(time_t timestamp, int32_t* year, int32_t* month, int32_t* mday, int32_t* hour, int32_t* minute, int32_t* second, int32_t zone)
- {
- timestamp += zone*3600;
- struct tm tmresult;
- if(NULL==gmtime_r(×tamp, &tmresult))
- return -1;
- if(NULL!=year)
- *year = tmresult.tm_year + 1900;
- if(NULL!=month)
- *month = tmresult.tm_mon + 1;
- if(NULL!=mday)
- *mday = tmresult.tm_mday;
- if(NULL!=hour)
- *hour = tmresult.tm_hour;
- if(NULL!=minute)
- *minute = tmresult.tm_min;
- if(NULL!=second)
- *second = tmresult.tm_sec;
- return 0;
- }
复制代码 这样调用- util_time(stamp, &year, &mon, &mday, &hour, &minute, &second, 8);
复制代码 然后自己sprintf一下就可以了 |
|