C++ stat处理文件属性

用stat函数可以得到诸如修改时间,所有者,文件权限等文件属性。

wgs2sgf在处理对局日期时,由于无法在wgs文件中找到对局时间方面的信息,受贴吧一大神启发,将文件的修改时间作为对局日期:

windows中需要用MinGW编译。

下面是函数参考:

时间的转换

日期贮存结构date

时间贮存结构time

char *ctime(long *clock)

本函数把clock所指的时间(如由函time返回的时间)转换成数下列格式的字符串:
Mon Nov 21 11:31:54 1983n
char asctime(struct tm *tm)
本函数把指定的tm结构类的时间转换成下列格式的字符串:
Mon Nov 21 11:31:54 1983n
double difftime(time_t time2,time_t time1)
计算结构time2和time1之间的时间差距(以秒为单位)
struct tm *gmtime(long *clock)
本函数把clock所指的时间(如由函数time返回的时间)转换成格林威治时间,并以tm结构形式返回
struct tm *localtime(long *clock)
本函数把clock所指的时间(如函数time返回的时间)转换成当地标准时间,并以tm结构形式返回
void tzset()本函数提供了对UNIX操作系统的兼容性
long dostounix(struct date *dateptr,struct time *timeptr)
本函数将dateptr所指的日期,timeptr所指的时间转换成UNIX格式, 并返回自格林威治时间1970年1月1日凌晨起到现在的秒数
void unixtodos(long utime,struct date *dateptr,struct time *timeptr)
本函数将自格林威治时间1970年1月1日凌晨起到现在的秒数utime转换成DOS格式并保存于用户所指的结构dateptr和timeptr中
void getdate(struct date *dateblk)
本函数将计算机内的日期写入结构dateblk中以供用户使用
void setdate(struct date *dateblk)
本函数将计算机内的日期改成由结构dateblk所指定的日期
void gettime(struct time *timep)
本函数将计算机内的时间写入结构timep中, 以供用户使用
void settime(struct time *timep)
本函数将计算机内的时间改为由结构timep所指的时间
long time(long *tloc)
本函数给出自格林威治时间1970年1月1日凌晨至现在所经过的秒数,并将该值存于tloc所指的单元中.
int stime(long *tp)本函数将tp所指的时间(例如由time所返回的时间)写入计算机中.

参考:http://www.cnblogs.com/king_astar/archive/2009/09/27/1575107.html

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注