Skip to content
Advertisement

linux c get system date format yyyymmdd

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.

Advertisement

Answer

You can convert from a string to a time structure using strptime (Linux only). This will set the time on a tm struct that is passed to it.

You can then use the ctime library. It will let you use difftime which will give you get the difference between two times.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement