日常工作中经常需要查看当前时间戳或者转换时间戳到日期,为此写了一个小工具,方便转换,分享给小伙伴!
#include<stdio.h>#include<stdlib.h>#include<sys/types.h>#include<time.h>intmain(intargc,char*argv[]){time_tnewtime;if(2==argc){newtime=strtol(argv[1],NULL,10);charszBuff[30];strftime(szBuff,sizeof(szBuff),"%Y/%m/%d%X",loc altime(&newtime));printf("%s\n",szBuff);}else{time(&newtime);printf("%ld\n",newtime);}exit(0);}
编译
gcc-Wall-oshowtimeshowtime.c
使用
chmod+xshowtimecpshowtime/usr/local/bin/showtimeshowtime1624964738