标准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 — 计算指 ...
随机推荐
- C#取调用堆栈StackTrace
Environment.StackTrace or System.Diagnostics.StackTrace if you need a more convienient (i.e. not str ...
- python模块学习之logging
filename:用指定的文件名创建FiledHandler(后边会具体讲解handler的概念),这样日志会被存储在指定的文件中. filemode:文件打开方式,在指定了filename时使用这个 ...
- github使用和推送到服务器端。。。
Alan Alan -- :: 第二节:创建一个仓库(Create A Repo Repositories) 直接在自己的登录后进入 github.com 首页就可以看到, 下面一栏有四步.用来创建 ...
- c#序列化和反序列化list
List<UserData> lstStuModel = new List<UserData>() { new UserData(){Name="001", ...
- [Tomcat]无法使用tomcat6.exe启动服务解决办法, The system cannot find the Registry key for service 'tomcat7'
重新配置环境变量后,可以使用startup.bat启动服务, 但是无法使用tomcat6.exe启动服务, 错误信息: [2011-03-10 18:51:49] [warn] The system ...
- Linux Linux程序练习三
/* index1 = 45 index2 = 36 index3 = 231 index4 = 43 index5 = 100 index6 = 123 index7 = 51 * * 通过读取读取 ...
- Linux 文件管理(C语言库函数二--程序日志)
文件删除和改名 int remove(const char *pathname); int rename(const char *oldpath,const char *newpath); remov ...
- tcp/iP协议族——IP工作原理及实例具体解释(下)
IP协议具体解释 上一篇文章文章主要介绍了IP服务的特点,IPv4头部结构IP分片.并用tcpdump抓取数据包,来观察IP数据报传送过程中IP的格式,以及分片的过程.本文主要介绍IP路由,IP ...
- PostgreSQL tips
tip 1 在sql中我们可以设置一个列自增长identity(1,1),但在postgresql中却没有这个关键字定义.但postgresql也有实现相关功能,那就是只需要将该列数据类型标记为ser ...
- Tomcat虚拟目录
x先来看一段server.xml文件里的配置: <Host appBase="" autoDeploy="true" debug="0" ...