Skip to content

Instantly share code, notes, and snippets.

@tmiz
Created April 16, 2011 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmiz/923190 to your computer and use it in GitHub Desktop.
Save tmiz/923190 to your computer and use it in GitHub Desktop.
n日後
#include <stdio.h>
#include <time.h>
struct mydate { int year,month,day; };
int addDay(struct mydate *d, int n)
{
struct tm birthday = {0,0,0,d->day,d->month,d->year-1900,0,0,0,0,NULL};
time_t birthday_sec = mktime(&birthday);
birthday_sec += (n*24*60*60);
struct tm *pHA = localtime( &birthday_sec );
if (pHA == NULL) return -1;
d->day = pHA->tm_mday;
d->month = pHA->tm_mon;
d->year = pHA->tm_year+1900;
return 0;
}
#ifdef _TEST
int main() {
struct mydate birthday = {2011,1,25};
if (addDay(&birthday, 100) >= 0) {
printf("%d/%d/%d\n", birthday.year,birthday.month, birthday.day);
}
return 0;
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment