[英]Embedding Unix date in a C program
I have a C program running on a Unix box. 我有一个在Unix机器上运行的C程序。
I would like to print a timestamp to an output file - at the moment I use the command date
to print the datetime on the terminal. 我想将时间戳打印到输出文件-目前,我使用命令
date
在终端上打印日期时间。
fprintf(outputfile, "%s ", date);
How do I go about doing this? 我该怎么做呢?
Use POSIX strftime(3) - format date and time for a C solution. 使用POSIX strftime(3)-格式化 C解决方案的日期和时间 。 It use the same format strings as
date(1)
它使用与
date(1)
相同的格式字符串
I also recommend you read the standard library intro(3) . 我还建议您阅读标准库intro(3) 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.