首页
/
每日頭條
/
科技
/
linux下将時間轉換成時間戳函數
linux下将時間轉換成時間戳函數
更新时间:2025-08-02 11:07:39

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

#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("%s\n",szBuff); } else { time(&newtime); printf("%ld\n",newtime); } exit(0); }

編譯

gcc -Wall -o showtime showtime.c

使用

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

linux下将時間轉換成時間戳函數(macos下好用的時間戳轉換小工具)1

,
Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
Copyright 2023-2025 - www.tftnews.com All Rights Reserved