0

我正在尝试根据时区获取时间。印度的偏移值为 5:30,因此我将使用“时间”函数获得的时间增加了 5 小时 30 分钟。但最终的答案总是给出 1 小时的偏移量。为什么 ?我应该如何纠正它?

#include <iostream>
#include <ctime>


int main() {

        time_t tNow;
        time(&tNow); 

        struct tm *now = localtime(&tNow);

        cout<<asctime(now)<<endl;

     // for Indian time (GMT 5:30) adding 5 to hour and 30 to min

        cout<< (now->tm_hour +5)%24 <<" "<< (now->tm_min +30)%60 <<" "<< now->tm_sec +0<< endl;


}

我应该做哪些改变来纠正这个问题?

4

0 回答 0