请问C语言中有无获取文件建立日期时间的函数

rebel888 2004-08-04 01:36:29
昨天晚上那个帖子出BUG了......重新请教

dir.h中的函数只能显示诸如“11145”之类的时间,但我们要求的是“04-08-03”和“23:12”这种格式的,请问有办法实现吗?
...全文
197 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
rebel888 2004-08-05
  • 打赏
  • 举报
回复
自己顶一下,希望能有人帮助。
rebel888 2004-08-04
  • 打赏
  • 举报
回复
请问具体应当怎么做?

比如我include了dir.h头文件后,定义struct ffblk ffblk,然后用ffblk.ff_ftime获取了文件建立时间后,怎么用localtime把它转化格式?具体的说,就是请写个实例供我参考一下可否?
peter9606 2004-08-04
  • 打赏
  • 举报
回复
gmtime
Syntax: #include <time.h>
struct tm *gmtime( const time_t *time );



The gmtime() function returns the given time in Coordinated Universal Time (usually Greenwich mean time), unless it's not supported by the system, in which case NULL is returned. Warning!

Related topics:
localtime(), time(), and asctime().
--------------------------------------------------------------------------------

localtime
Syntax: #include <time.h>
struct tm *localtime( const time_t *time );



The function localtime() converts calendar time time into local time. Warning!

Related topics:
gmtime(), time(), and asctime().
--------------------------------------------------------------------------------

mktime
Syntax: #include <time.h>
time_t mktime( struct tm *time );



The mktime() function converts the local time in time to calendar time, and returns it. If there is an error, -1 is returned.

Related topics:
time(), gmtime(), asctime(), and ctime().
--------------------------------------------------------------------------------

strftime
Syntax: #include <time.h>
size_t strftime( char *str, size_t maxsize, const char *fmt, struct tm *time );



The function strftime() formats date and time information from time to a format specified by fmt, then stores the result in str (up to maxsize characters). Certain codes may be used in fmt to specify different types of time:

Code Meaning
%a abbreviated weekday name
%A full weekday name
%b abbreviated month name
%B full month name
%c the standard date and time string
%d day of the month, as a number (1-31)
%H hour, 24 hour format (0-23)
%I hour, 12 hour format (1-12)
%j day of the year, as a number (1-366)
%m month as a number (1-12). Note: some versions of Microsoft Visual C++ may use values that range from 0-11.
%M minute as a number (0-59)
%p locale's equivalent of AM or PM
%S second as a number (0-59)
%U week of the year, sunday as the first day
%w weekday as a decimal (0-6, sunday=0)
%W week of the year, monday as the first day
%x standard date string
%X standard time string
%y year in decimal, without the century (0-99)
%Y year in decimal, with the century
%Z time zone name
%% a percent sign

The strftime() function returns the number of characters put into str, or zero if an error occurs.

Related topics:
time(), localtime(), and gmtime().
peter9606 2004-08-04
  • 打赏
  • 举报
回复
time
Syntax: #include <time.h>
time_t time( time_t *time );



The function time() returns the current time, or -1 if there is an error. If the argument time is given, then the current time is stored in time.


用time函数得到系统时间

localtime
Syntax: #include <time.h>
struct tm *localtime( const time_t *time );



The function localtime() converts calendar time time into local time. Warning!


当然了 你需要把得到的一个long int数字时间转换成一个比较好的格式输出到文档里面,你就用到了上面的转换时间的函数 当然了还有其他很多转换成各种各式的时间函数。
  • 打赏
  • 举报
回复
自己编一段程序修改一下结果不行吗?

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧