Didn"t forge 2018-11-05 06:30 采纳率: 25%
浏览 165

为什么本地时间()和 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 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算
    • ¥15 java如何提取出pdf里的文字?
    • ¥100 求三轴之间相互配合画圆以及直线的算法
    • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
    • ¥15 名为“Product”的列已属于此 DataTable