Chinaunix首页 | 论坛 | 博客
  • 博客访问: 263517
  • 博文数量: 51
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 606
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-13 16:43
文章分类

全部博文(51)

文章存档

2011年(1)

2010年(3)

2009年(45)

2008年(2)

我的朋友

分类: LINUX

2009-05-27 17:38:41

环境:
    SunOS solaris 5.10 Generic_139556-08 i86pc i386 i86pc
    Thread model: posix
    gcc version 3.4.3 (csl-sol210-3_4-branch+sol_rpath)  
man帮助说明是:  
%C       Century number (the year divided by 100  and  trun-
              cated to an integer as a decimal number [01,99]).
目的:需要格式20090101.
例子:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
main()
{
    time_t t;
    time ( &t );
    char machine_date[17];
    t = time(0);
    cftime(machine_date,"%C%y%d%m",&t);

    //cftime(machine_date,"%Y%d%m",&t);
    printf("[%s]\n",machine_date);
}

%C输出:

   [Wed May 27 17:38:10 CST 2009092705]

%Y才是需要的:

   [20072705]

阅读(2040) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~