用C语言从1970年1月1日转换秒日期 [英] Convert seconds from Jan 1st 1970 to date using C language
本文介绍了用C语言从1970年1月1日转换秒日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
C程序秒转换为日期。
我有以下的C程序code。
C program to convert seconds to Date. I have the following C program code.
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#ifdef HAVE_ST_BIRTHTIME
# define birthtime(x) (x).st_birthtime
#else
# define birthtime(x) (x).st_ctime
#endif
int main(int argc, char *argv[])
{
struct stat st;
size_t i;
for( i=1; i<argc; i++ )
{
if( stat(argv[i], &st) != 0 )
perror(argv[i]);
printf("%i\n", birthtime(st));
}
return 0;
}
,返回时间,以秒为从文件创建日期1970年1月1日。我如何用C语言秒转换为创建日期只?
It returns time in seconds from Jan 1st 1970 to the file creation date. How do I convert the seconds to date of creation using C language only?
推荐答案
标准C函数转换秒时代以来到分解的时候,是本地时间()
或 gmtime的()
,根据您的需要。然后,您可以使用 asctime()
来分解时间转换为字符串。不要忘了的#include&LT; time.h中方式&gt;
并读取相应的手册页
The Standard C function to convert seconds since the epoch to a broken down time, is localtime()
or gmtime()
, depending on your needs. You might then use asctime()
to convert broken down times to a string. Don't forget to #include <time.h>
and read the corresponding manual pages.
这篇关于用C语言从1970年1月1日转换秒日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文