C语言获取当前时间
创始人
2025-01-08 05:34:46
0

一共有两段代码,一个是获取当前时间,一个是获取到现在的总毫秒数求关注😄 互粉必回

获取当前时间

#include

#include

int main() {

    time_t rawtime;

    struct tm * timeinfo;

    char buffer[20];

    // 获取当前时间

    time(&rawtime);

    timeinfo = localtime(&rawtime);

    // 使用 strftime 来格式化时间

    strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", timeinfo);

    // 输出格式化后的时间

    printf("当前时间是: %s\n", buffer);

    return 0;

}

获取到现在的总毫秒数

#include

#include

#include

int main() {

    struct timeval tv;

    struct tm *now;

    long total_milliseconds;

    // 获取当前时间

    gettimeofday(&tv, NULL);

    // 将时间戳转换为可读的tm结构体

    now = localtime(&tv.tv_sec);

    // 计算总毫秒数

    total_milliseconds = (now->tm_year + 1900) * 31536000000L; // 一年大约有31536000000毫秒

    total_milliseconds += (now->tm_mon + 1) * 2628000000L; // 一个月大约有2628000000毫秒

    total_milliseconds += now->tm_mday * 86400000L; // 一天有86400000毫秒

    total_milliseconds += now->tm_hour * 3600000L; // 一小时有3600000毫秒

    total_milliseconds += now->tm_min * 60000L; // 一分钟有60000毫秒

    total_milliseconds += now->tm_sec * 1000L; // 一秒有1000毫秒

    total_milliseconds += tv.tv_usec / 1000; // 将微秒转换为毫秒

    // 输出总毫秒数

    printf("总毫秒数: %ld\n", total_milliseconds);

    return 0;

}

相关内容

热门资讯

wepower有外挂!hhpo... wepower有外挂!hhpoker德州有挂(透视)存在挂教程(有挂猫腻)-哔哩哔哩;1、超多福利:...
wepokeai机器人!wej... wepokeai机器人!wejoker透视方法(透视)细节揭秘(确实有挂)-哔哩哔哩;亲真的是有正版...
wepokeai代打的胜率!p... wepokeai代打的胜率!pokermaster脚本(透视)黑科技教程(有挂秘笈)-哔哩哔哩是一款...
wepoke黑科技!德普之星透... wepoke黑科技!德普之星透视辅助软件是真的(透视)教你攻略(有挂方略)-哔哩哔哩是一款可以让一直...
wepoke是真的有挂!hh ... wepoke是真的有挂!hh poker辅助有用(透视)细节方法(有挂功能)-哔哩哔哩;最新版202...
wepokeai代打逻辑!po... wepokeai代打逻辑!pokemmo手机版脚本免费(透视)透明教程(真的有挂)-哔哩哔哩;是一款...
wepoke有app软件!we... wepoke有app软件!wepoker辅助工具(透视)透牌教程(有挂分析)-哔哩哔哩;wepoke...
wepok软件透明挂!哈糖大菠... 【福星临门,好运相随】;wepok软件透明挂!哈糖大菠萝软件下载(透视)2025新版教程(揭秘有挂)...
七分钟了解!新畅游互娱科技(辅... 七分钟了解!新畅游互娱科技(辅助挂)详细透视开挂辅助新2025版(切实真的有挂)-哔哩哔哩;1、首先...
wepokeai代打逻辑!德州... wepokeai代打逻辑!德州hhpoker脚本(透视)辅助教程(有挂秘笈)-哔哩哔哩;是一款可以让...