それでは、あなたはあなたがmktime
とlocaltime
などの<ctime>
functionsを利用し、毎日あなたが必要なものを行うには86400秒を持っていることを確信することができます
int year = 2015;
int month = 2;
int day = 12;
int offset = 1000;
を持っているとしましょう。このようなもの。
#include <ctime>
struct tm orig_date;
orig_date->tm_sec = 0;
orig_date->tm_min = 0;
orig_date->tm_hour = 12; /* midday, so we make space for non-86400 errors */
orig_date->tm_mday = day;
orig_date->tm_mon = month - 1; /* uses 0-11 range */
orig_date->tm_year = year;
orig_date->tm_isdst = 0;
time_t utc = mktime(&orig_date);
utc += (offset * 86400);
struct tm *new_date;
new_date = localtime(&utc);
printf("Old date: %d. %d. %d\n", orig_date.tm_mday, orig_date.tm_mon, orig_date.tm_year);
printf("New date: %d. %d. %d\n", new_date->tm_mday, new_date->tm_mon, new_date->tm_year);
コードは(私が正しいことが確認さ)を、次の生成されます。
Old date: 12. 1. 2015
New date: 8. 10. 2017
これは宿題のタスクですか?ほとんど同じ質問(同じタグさえも)はあなたとほぼ同じ時間に尋ねました:http://stackoverflow.com/questions/36372774/date-and-time-manipulation – dfri