标准c时间与日期函数


asctime

语法:

 
  #include <time.h>
  char *asctime( const struct tm *ptr );

功能: 函数将ptr所指向的时间结构转换成下列字符串:

    day month date hours:minutes:seconds year\n\0

例如:

    Mon Jun 26 12:03:53 2000

相关主题: localtime(), gmtime(), time(), and ctime().


clock

语法:

 
  #include <time.h>
  clock_t clock( void );

功能:函数返回自程序开始运行的处理器时间,如果无可用信息,返回-1。 转换返回值以秒记, 返回值除以CLOCKS_PER_SECOND. (注: 如果编译器是POSIX兼容的, CLOCKS_PER_SECOND定义为1000000.)

相关主题: time(), asctime(), and ctime().


ctime

语法:

 
  #include <time.h>
  char *ctime( const time_t *time );

功能:函数转换参数time为本地时间格式:

    day month date hours:minutes:seconds year\n\0

ctime() 等同

    asctime( localtime( tp ) );

相关主题: localtime(), gmtime(), time(), and asctime().


difftime

语法:

 
  #include <time.h>
  double difftime( time_t time2, time_t time1 );

功能:函数返回时间参数time2time1之差的秒数表示。

相关主题: localtime(), gmtime(), time(), and asctime().


gmtime

语法:

 
  #include <time.h>
  struct tm *gmtime( const time_t *time );

功能:函数返回给定的统一世界时间(通常是格林威治时间),如果系统不支持统一世界时间系统返回NULL。 警告!

相关主题: localtime(), time(), and asctime().


localtime

语法:

 
  #include <time.h>
  struct tm *localtime( const time_t *time );

功能:函数返回本地日历时间。警告!

相关主题: gmtime(), time(), and asctime().


mktime

语法:

 
  #include <time.h>
  time_t mktime( struct tm *time );

功能:函数转换参数time 类型的本地时间至日历时间,并返回结果。如果发生错误,返回-1。

相关主题: time(), gmtime(), asctime(), and ctime().


strftime

语法:

 
  #include <time.h>
  size_t strftime( char *str, size_t maxsize, const char *fmt, struct tm *time );

功能:函数按照参数fmt所设定格式将time类型的参数格式化为日期时间信息,然后存储在字符串str中(至多maxsize 个字符)。用于设定时间不同类型的代码为:

代码

含义

%a

星期的缩略形式

%A

星期的完整形式

%b

月份的缩略形式

%B

月份的完整形式

%c

月份的缩略形式

%d

月中的第几天(1-31)

%H

小时, 24小时格式 (0-23)

%I

小时, 12小时格式  (1-12)

%j

年中的第几天(1-366)

%m

月份 (1-12). Note: 某些版本的Microsoft Visual C++ 可能使用取值范围0-11.

%M

分钟(0-59)

%p

本地时间的上午或下午(AM or PM)

%S

秒钟(0-59)

%U

年中的第几周,星期天是一周的第一天

%w

星期几的数字表示(0-6, 星期天=0)

%W

一年中的第几周,星期天是一周的第一天

%x

标准日期字符串

%X

标准时间字符串

%y

年(0-99)

%Y

用CCYY表示的年(如:2004)

%Z

时区名

%%

百分号

函数strftime()返回值为处理结果字符串str中字符的个数,如果发生错误返回零。

相关主题: time(), localtime(), and gmtime().


time

语法:

 
  #include <time.h>
  time_t time( time_t *time );

功能: 函数返回当前时间,如果发生错误返回零。如果给定参数time ,那么当前时间存储到参数time中。

相关主题: localtime(), gmtime(), strftime(), ctime(),

标准c时间与日期函数的更多相关文章

  1. C++ 第十课:标准c时间与日期函数

    asctime() 时间文本格式 clock() 返回自程序开始运行所经过的时间 ctime() 返回特定格式时间 difftime() 两时刻的间隔 gmtime() 返回指向当前格林威治时间的指针 ...

  2. Python 关于时间和日期函数使用 -- (转)

    python中关于时间和日期函数有time和datatime   1.获取当前时间的两种方法: import datetime,time now = time.strftime("%Y-%m ...

  3. lua的时间和日期函数

    lua的时间和日期函数 -- ::| 分类: Lua | 标签:lua 时间 函数 |举报|字号 订阅 下载LOFTER客户端 --获取当前的时间戳,单位是秒. time=os.time(); pri ...

  4. mysql 中时间和日期函数应用

    一.MySQL 获得当前日期时间 函数 1.1 获得当前日期+时间(date + time)函数:now() mysql> select now(); +-------------------- ...

  5. [转]详细的mysql时间和日期函数

    这里是一个使用日期函数的例子.下面的查询选择了所有记录,其date_col的值是在最后30天以内: mysql> SELECT something FROM table WHERE TO_DAY ...

  6. mysql 中 时间和日期函数

    From: http://www.cnblogs.com/redfox241/archive/2009/07/23/1529092.html 一.MySQL 获得当前日期时间 函数 1.1 获得当前日 ...

  7. PHP之时间和日期函数

    // 时间日期函数 Time <?php date_default_timezone_set('UTC'); // 获取当前时间的时间戳 $time0 = mktime(); $time1 = ...

  8. python 时间及日期函数

    本人最近新学python ,用到关于时间和日期的函数,经过一番研究,从网上查找资料,经过测试,总结了一下相关的方法. import timeimport datetime '''时间转化为时间戳: 2 ...

  9. php第五节(字符串函数和时间、日期函数)

    <?php //查找字符串函数 // strpos() 查找字符第一次出现的位置 重点区分大小写 //stripos — 查找字符串首次出现的位置(不区分大小写) //strrpos — 计算指 ...

随机推荐

  1. Closure闭包示例

    var foo = function(){ var cnt = 0; return function(){ return cnt++; }; }; var closure = foo(); conso ...

  2. url传递参数

    url:'/randowCode?t='+Math.random(); //当给某个赋值可以: $('#change').click(function(){ $("#codeimage&qu ...

  3. out传值

    public void Out(out int a, out int b)        {//out相当于return返回值            //可以返回多个值            //拿过 ...

  4. DataUml Design 介绍8-DataUML 1.2版本正式发布(支持SQLite数据库、NetUML开发框架)

    DataUML 1.2版本在软件架构上有了很大的变化,目前DataUML支持Access.SQLite.MY SQL .ORACLE.MS SERVER2000.MS SERVER2005.MS SE ...

  5. IOS设计模式的六大设计原则之接口隔离原则(ISP,Interface Segregation Principle)

    定义 客户端不应该依赖它不需要的接口: 一个类对另一个类的依赖应该建立在最小的接口上. 定义解读 定义包含三层含义: 一个类对另一个类的依赖应该建立在最小的接口上: 一个接口代表一个角色,不应该将不同 ...

  6. 在海思hisiv100nptl平台上交叉编译并安装SRS

    ./configure --with-arm-ubuntu12 && make 须要安装: apt-get installgcc-arm-linux-gnueabi     ,但hi3 ...

  7. easy_UI datagrid view数据格式化

    从数据库中提取的信息,有时候需要后期处理一下,easy_ui给了我们很好的一个方法,根据easy_ui生成datagridview的两种方式,下面用两种方式来格式化显示数据信息 1,通过脚本生成的da ...

  8. java.lang.IllegalArgumentException: column '_id' does not exist问题的解决方案

    我在使用SimpleCursorAdapter的过程中遇到了问题: java.lang.IllegalArgumentException: column '_id' does not exist 这个 ...

  9. Eclipse 浏览(Navigate)菜单

    浏览 Eclipse 工作空间 浏览(Navigate)菜单提供了多个菜单可以让你快速定位到指定资源. 上图中 Open Type, Open Type in Hierarchy 和 Open Res ...

  10. Java 学习笔记及资源

    Spring框架入门HelloWorld :http://www.importnew.com/13246.html  (iteye 唐 博客,跟我学Sprint) Spring 框架下载地址:http ...