You can use utimes .
If the time is not NULL, it is assumed that it points to an array of two time intervals of structures. The access time is set to the value of the first element, and the modification time is set to the value of the second element.
and
For file systems that support file birth time (creation) (for example, UFS2), the time of birth will be set to the value of the second element if the second element is older than the current time of birth. Set both birth time and modification time, two calls are required; the first to set the time of birth and the second to set the (supposedly newer) modification time
As an example:
struct timeval times[2]; memset(times, 0, sizeof(times)); times[0].seconds = 946684799; /* 31 Dec 1999 23:59:59 */ times[1].seconds = 946684799; utimes("/path/to/file", ×);
If the elapsed modification time is outdated than the current file creation time, the creation time will be set. You can call utimes again if you want to set a different modification time.
source share