unix时间戳在线转换工具使用 unix时间戳转换公式
2021-11-09 03:27:50 爱问问
日常工作中经常需要查看当前时间戳或者转换时间戳到日期,为此写了一个小工具,方便转换,分享给小伙伴,喜欢的请关注并点赞!
#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
声明:此文信息来源于网络,登载此文只为提供信息参考,并不用于任何商业目的。如有侵权,请及时联系我们:baisebaisebaise@yeah.net