如何st

编程入门 行业动态 更新时间:2024-10-13 06:19:17
本文介绍了如何st_mtime(从统计功能得到)转换为字符串或字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我要st_mtime转换为字符串格式为它传递到Java层,我尝试用这个例子的 www.cplusplus/forum/unices/10342/ 但是编译器产生误差

I need to convert st_mtime to string format for passing it to java layer, i try to use this example www.cplusplus/forum/unices/10342/ but compiler produce errors

这是'长无符号整数*'到'const的time_t的* {又名无效的转换  长整型常量*}

invalid conversion from 'long unsigned int*' to 'const time_t* {aka long int const*}'

初​​始化的参数1'TM *本地时间(常量的time_t *)'  [-fpermissive]

initializing argument 1 of 'tm* localtime(const time_t*)' [-fpermissive]

我做错了什么,如何在字符串presentation使用统计函数得到的时间创建的文件。

What i doing wrong, how to get time creation of file using stat function in string presentation.

请帮助。

推荐答案

据该的 STAT(2)手册页,在 st_mtime 字段是 time_t的(即后阅读时间(7)手册页,一些由于 Unix纪元)秒。

According to the stat(2) man page, the st_mtime field is a time_t (i.e. after reading the time(7) man page, a number of seconds since the unix Epoch).

您需要本地时间(3)以将其转换 time_t的到结构TM 在当地的时间,那么,的的strftime(3)将其转换为一个的char * 字符串

You need localtime(3) to convert that time_t to a struct tm in local time, then, strftime(3) to convert it to a char* string.

所以,你可以code是这样的:

So you could code something like:

time_t t = mystat.st_mtime; struct tm lt; localtime_r(&t, &lt); char timbuf[80]; strftime(timbuf, sizeof(timbuf), "%c", &lt);

然后用 timbuf 按的strdup 也许-ing它。

NB。我使用则localtime_r ,因为它更线程友好。

NB. I am using localtime_r because it is more thread friendly.

更多推荐

如何st

本文发布于:2023-10-08 15:01:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472972.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:st

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!