参考如下:
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std
void main( int argc,char* argv[] )
{
if(argc<2)
{
cout<<"No arguments"<<endl
exit(1)
}
string file1,file2
file1=argv[1]
file2=argv[2]
struct stat buf1
struct stat buf2
int result1,result2
//获得文件状态信息
result1 =stat( file1.c_str(), &buf1 )
result2 =stat( file2.c_str(), &buf2 )
//显示文件状态信息
if( result1 != 0 )
perror( "显示文件状态信息出错" )
else
{
cout<<"最后修改日期1:"<<ctime(&buf1.st_mtime)
}
//显示文件状态信息
if( result1 != 0 )
perror( "显示文件状态信息出错" )
else
{
cout<<"最后修改日期2:"<<ctime(&buf2.st_mtime)
}
buf2.st_mtime=buf1.st_mtime
cout<<"最后修改日期3:"<<ctime(&buf2.st_mtime)
}
1、函数名:settime
功
能:
设置系统时间
原型:void
settime
2、例程:
#include <stdio.h>
#include <dos.h>
int main(void)
{
struct time t
gettime(&t)
printf("The current minute is: %d\n", t.ti_min)
printf("The current hour is: %d\n", t.ti_hour)
printf("The current hundredth of a second is: %d\n", t.ti_hund)
printf("The current second is: %d\n", t.ti_sec)
/* Add one to the minutes struct element and then call settime */
t.ti_min++
settime(&t)//设置系统时间
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)