I want ask some questions 1) I want get string yyyymmdd of system date using linux c how should I do it ? And I want use this string do some arithmetic, like I have "20160317" I want do 20160317 - 90 get a new date,pls help
2)
int n;
int m;
n = (m%10 = 0)?(m/10):(m/10+1);
is there some cleaner way to do this? like if m = 11 n will get 2, m = 10 n will get 1.
Consider c standard function. strftime
#include <time.h>
char datename[32];
struct tm* to;
time_t t;
t = time(NULL);
to = localtime(&t);
strftime(datename, sizeof(datename), "%Y%m%d", to);
if you want date of 90 days before. just
t -= 90 * 24 * 3600;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.