unix時間戳在線轉換工具使用「unix時間戳轉換公式」

日常工作中經常需要查看當前時間戳或者轉換時間戳到日期,為此寫了一個小工具,方便轉換,分享給小夥伴,喜歡的請關注並點贊!

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>

int main(int argc,char *argv[]) {
    time_t newtime;

    if (2 == argc) {
        newtime = strtol(argv[1],NULL,10);
        char szBuff[30];
        strftime(szBuff, sizeof(szBuff), "%Y/%m/%d %X", localtime(&newtime));
        printf("%sn",szBuff);
    }
    else {
        time(&newtime);
        printf("%ldn",newtime);
    }

    exit(0);
}

編譯

gcc -Wall -o showtime showtime.c

使用

chmod +x showtime
cp showtime /usr/local/bin/

showtime
showtime 1624964738
linux/macos下好用的時間戳轉換小工具

原創文章,作者:投稿專員,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/252704.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
投稿專員的頭像投稿專員
上一篇 2024-12-14 02:18
下一篇 2024-12-14 02:18

相關推薦

發表回復

登錄後才能評論