APUE之格式化time_t得到文件时间信息

vi 1.0.c

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <time.h>
#define BUF 100


void print_time(time_t ct,char* s)
{
    char st[BUF];
    printf("%s: ",s);
    strftime(st,BUF,"%Y %x %X",localtime(&ct));
    printf("%s\n",st);
}

int main(int argc,char* argv[])
{
    if (argc != 2)
    {
    printf("you need <pathname>\n");
    exit(0);
    }

    struct stat statbuf;

    if (lstat(argv[1],&statbuf) < 0)
    {
    printf("lstat error\n");
    exit(0);
    }

    char *s = "文件最后访问时间为";
    print_time(statbuf.st_atime,s);

    s = "文件最后修改时间为";
    print_time(statbuf.st_mtime,s);

    s = "文件最后状态改变时间为";
    print_time(statbuf.st_ctime,s);
}

运行:

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...