Created
February 3, 2014 11:30
-
-
Save apraga/8782374 to your computer and use it in GitHub Desktop.
How to manage date in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <time.h> | |
#include <stdio.h> | |
int main (void) { | |
time_t cur; | |
time_t next; | |
struct tm curtime; | |
struct tm nexttime; | |
curtime.tm_hour = 01; | |
curtime.tm_min = 0; | |
curtime.tm_sec = 0; | |
curtime.tm_mday = 27; | |
curtime.tm_mon = 1; | |
curtime.tm_year = 2003-1900; | |
/* Normalize time (fill missing info)*/ | |
cur = mktime(&curtime); | |
nexttime = curtime; | |
next = mktime(&nexttime); | |
/* From February, 27th to March 1st*/ | |
next = cur + 2*24*3600; | |
//fputs (asctime (&curtime), stdout); | |
//fputs (asctime (&nexttime), stdout); | |
fputs (ctime (&cur), stdout); | |
fputs (ctime (&next), stdout); | |
//printf("%.f %d\n", difftime(next, cur), next-cur); | |
return 0; | |
} | |
========================================================= | |
Result : | |
Thu Feb 27 01:00:00 2003 | |
Sat Mar 1 01:00:00 2003 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment