标准c时间与日期函数
标准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 ); |
功能:函数返回时间参数time2和time1之差的秒数表示。
相关主题: 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时间与日期函数的更多相关文章
- C++ 第十课:标准c时间与日期函数
asctime() 时间文本格式 clock() 返回自程序开始运行所经过的时间 ctime() 返回特定格式时间 difftime() 两时刻的间隔 gmtime() 返回指向当前格林威治时间的指针 ...
- Python 关于时间和日期函数使用 -- (转)
python中关于时间和日期函数有time和datatime 1.获取当前时间的两种方法: import datetime,time now = time.strftime("%Y-%m ...
- lua的时间和日期函数
lua的时间和日期函数 -- ::| 分类: Lua | 标签:lua 时间 函数 |举报|字号 订阅 下载LOFTER客户端 --获取当前的时间戳,单位是秒. time=os.time(); pri ...
- mysql 中时间和日期函数应用
一.MySQL 获得当前日期时间 函数 1.1 获得当前日期+时间(date + time)函数:now() mysql> select now(); +-------------------- ...
- [转]详细的mysql时间和日期函数
这里是一个使用日期函数的例子.下面的查询选择了所有记录,其date_col的值是在最后30天以内: mysql> SELECT something FROM table WHERE TO_DAY ...
- mysql 中 时间和日期函数
From: http://www.cnblogs.com/redfox241/archive/2009/07/23/1529092.html 一.MySQL 获得当前日期时间 函数 1.1 获得当前日 ...
- PHP之时间和日期函数
// 时间日期函数 Time <?php date_default_timezone_set('UTC'); // 获取当前时间的时间戳 $time0 = mktime(); $time1 = ...
- python 时间及日期函数
本人最近新学python ,用到关于时间和日期的函数,经过一番研究,从网上查找资料,经过测试,总结了一下相关的方法. import timeimport datetime '''时间转化为时间戳: 2 ...
- php第五节(字符串函数和时间、日期函数)
<?php //查找字符串函数 // strpos() 查找字符第一次出现的位置 重点区分大小写 //stripos — 查找字符串首次出现的位置(不区分大小写) //strrpos — 计算指 ...
随机推荐
- 自己实现strcpy函数
#include //printf #include //ssert #include //malloc #include //strlen char * sstrcpy(char * strdst, ...
- 【转载】Highcharts使用指南
另附几个较好的图形组件库: 基于HTML5的开源画图组件:http://www.ichartjs.com/gettingstarted/ 图表Echarts: http://echarts.baidu ...
- CentOS 7 安装以及配置桌面环境
一.安装 GNOME 桌面 1.安装命令: yum groupinstall "GNOME Desktop" "X Window System" " ...
- tcp3握手,作用,syn攻击
tcp建立链接3次握手: 1.客户端→服务端,发送seq=x,syn=1 2.服务端→客户端,发送seq=y,syn=1,ack=x+1 3.客户端→服务端,发送seq=z,ack=y+1 三次握手作 ...
- hive中的join
建表 : jdbc:hive2://localhost:10000> create database myjoin; No rows affected (3.78 seconds) : jdbc ...
- 华为终端开放实验室Android Beta 4测试能力上线
7月26日,Android P Beta 4发布(即Android P DP5),此版本为开发者最后一个预览版本,也预示着Android P正式版即将与大家见面. 为保证开发者在正式版本来临前做 ...
- IOS设计模式的六大设计原则之迪米特法则(LOD,Law Of Demeter)
定义 狭义的迪米特法则定义:也叫最少知识原则(LKP,Least Knowledge Principle).如果两个类不必彼此直接通信,那么这两个类就不应当发生直接的相互作用.如果其中的一个类需要调用 ...
- Eclipse Debug 配置
创建和使用 Debug 配置 Eclipse Debug 配置类似于运行配置但它是用于在调试模式下开启应用. 打开 Debug 配置对话框步骤为:Run > Debug Configuratio ...
- ActiveMQ部署步骤和后台管理网站Service Unavailable问题解决笔记
最近部署ActiveMQ的时候,发现有的服务器可以打开后台管理网址,有的服务器无法打开,Jetty报503 Service Unavailable. 搞了很久终于发现了问题,现将部署和解决过程做笔记如 ...
- apache2+svn Expected FS format '2'; found format '3'
format格式与svn版本号我猜对应如下: 1.4.x 对应 format 2 1.5.x 对应 format 3 …… 1.8.x 对应 format 6 那么每个format创建出的repo要用 ...