当前位置:首页 > 网络编程 > 软件语言 > C语言 > c语言Date_time库函数学习

c语言Date_time库函数学习

点击次数:36 次 发布日期:2008-12-01 11:57:05 作者:源代码网
源代码网推荐 /*
  #include <time.h>
  time_t time( time_t *time );
    函数time()返回当前时间
    若参数time给定,则当前时间存储在time指针中
    在VC中,若需要给定time参数,并且返回值和time储存值相同,或是赋予NULL的值
    time_t类型即long类型,其值是系统从1970年1月1日00:00:00到现在总共的秒数

  #include <time.h>
  struct tm *localtime( const time_t *time );
    函数将time的值转换为当地时间,用结构体tm存储
    time的值可有上诉函数time()获取
    该函数可结合下面的函数使用

  #include <time.h>
  char *asctime( const struct tm *ptr );
    将结构体*ptr的内容转换为如下形式的字符串
        day month date hours:minutes:seconds year
      eg.
        Mon Sep 24 16:18:20 2007

  #include <time.h>
  size_t strftime( char *str, size_t maxsize, const char *fmt, struct tm *time );
    函数以fmt的特定格式将time格式化后存储在str字符串中
        %a abbreviated weekday name (e.g. Fri)  
        %A full weekday name (e.g. Friday)  
        %b abbreviated month name (e.g. Oct)  
        %B full month name (e.g. October)  
        %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)   [Page]
        %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, (0-53), where week 1 has the first Sunday  
        %w weekday as a decimal (0-6), where Sunday is 0  
        %W week of the year, (0-53), where week 1 has the first Monday  
        %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  

  #include <time.h>
  time_t mktime( struct tm *time );
    函数将结构体参数time转换为从1970年1月1日到现在时间的秒数
    它是time的相反函数

  #include <time.h>
  struct tm *gmtime( const time_t *time );
    函数将time转换为结构体tm的形式存储,以Coordinated Universal Time的形式
    与localtime函数类似

  #include <time.h>
  double difftime( time_t time2, time_t time1 ); 源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华