如何在c中将时间转换为ac字符串?
我想在 .c 文件中的 .txt 文件中写入一些内容,但需要使用当前时间戳作为后缀来命名该文件,就像 filename_2010_08_19_20_30 一样。所以我得先定义文件名字符数组,然后自己处理文件名?一个一个分配字符?
有什么简单的方法可以做到这一点吗?
I wanna to write something to a .txt file in .c file, but required to name that file with the current timestamp as the postfix, just like filename_2010_08_19_20_30. So I have to define the filename char array first and process the filename by myself?Assign the character one by one?
Is there any easy way to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有一个名为
strftime
的函数,其存在的明确目的是将时间值写入人类可读的字符串。文档:http://linux.die.net/man/3/strftime例子:
There's a function called
strftime
that exists for the express purpose of writing a time value into a human-readable string. Documentation: http://linux.die.net/man/3/strftimeAn example:
查看 strftime 函数:
http://www.cplusplus.com/reference/clibrary /ctime/strftime/
Check out the strftime function:
http://www.cplusplus.com/reference/clibrary/ctime/strftime/