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

为什么本地时间()和 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 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试,帮帮忙吧
    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建