胖鸭 2018-11-05 06:30
浏览 157

为什么本地时间()和 gmity 在 c 中给出相同的结果?

I'm trying to write a function that takes a time_t as an argument and prints the date and time in GMT and in local time. However, gmtime() and localtime() are both giving GMT time. I've tried the things that have been suggested on a couple of pages, but I'm still getting GMT for both.

Here is my code:

#include <stdio.h>
#include <time.h>

void printDateOfTime(time_t t);

int main(void)
{
    time_t now;
    now = time(NULL);
    printDateOfTime(now);
    return 0;
}

void printDateOfTime(time_t t)
{
    struct tm* gTime;
    struct tm* lTime;

    lTime = localtime(&t);
    printf("Local: %s\n", asctime(lTime));

    gTime = gmtime(&t);
    printf("GMT: %s\n", asctime(gTime));
}

I'm in the Eastern Standard Timezone (5 hours behind GMT), and here is the output I'm getting:

Local: Mon Nov  5 06:18:57 2018

GMT: Mon Nov  5 06:18:57 2018

转载于:https://stackoverflow.com/questions/53149399/why-are-localtime-and-gmtime-giving-same-result-in-c

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条