struct tm->time() localtime() gmtime()
struct tm->time() localtime() gmtime()

struct tm {
int tm_sec; /*代表目前秒数,正常范围为0-59,但允许至61秒 */
int tm_min; /*代表目前分数,范围0-59*/
int tm_hour; /*从午夜算起的时数,范围为0-23*/
int tm_mday; /*目前月份的日数,范围01-31*/
int tm_mon; /*代表目前月份,从一月算起,范围从0-11*/
int tm_year; /*从1900 年算起至今的年数*/
int tm_wday; /*一星期的日数,从星期一算起,范围为0-6 */
int tm_yday; /*从今年1月1日算起至今的天数,范围为0-365*/
int tm_isdst; /*日光节约时间的旗标*/
};

time()
#ifndef _TIME_T_DEFINED
typedef long time_t; /* time value */
#define _TIME_T_DEFINED /* avoid multiple defines of time_t */
#endif

#include <stdio.h>
#include <stddef.h>
#include <time.h>
int main(void)
{
time_t timer;//time_t就是long int 类型
struct tm *tblock;
timer = time(NULL);//这一句也可以改成time(&timer);
tblock = localtime(&timer);
printf("Local time is: %s\n",asctime(tblock));
return 0;
}


#include<time.h>
#include<stdio.h>
int main()
{
struct tm *t;
time_t tt;
time(&tt);
t=localtime(&tt);
printf("%4d年%02d月%02d日 %02d:%02d:%02d\n",t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
return 0;
}

gmtime()

#include "stdio.h"
#include "time.h"
#include "stdlib.h"
int main(void)
{
time_t t;
struct tm *gmt, *area;
tzset(); /* tzset()*/
t = time(NULL);
area = localtime(&t);
printf("Local time is: %s", asctime(area));
gmt = gmtime(&t);
printf("GMT is: %s", asctime(gmt));
return 0;
}
struct tm->time() localtime() gmtime()的更多相关文章
- C语言中两种方式表示时间日期值time_t和struct tm类型的相互转换
使用gmtime函数或localtime函数将time_t类型的时间日期转换为structtm类型: 使用time函数返回的是一个long值,该值对用户的意义不大,一般不能根据其值确定具体的年.月.日 ...
- 【转】C/C++中的日期和时间 TIME_T与STRUCT TM转换——2013-08-25 16
http://www.cnblogs.com/Wiseman/archive/2005/10/24/260576.html 摘要: 本文从介绍基础概念入手,探讨了在C/C++中对日期和时间操作所用到的 ...
- struct tm 和 time_t 时间和日期的使用方法(转
关键字:UTC(世界标准时间),Calendar Time(日历时间),epoch(时间点),clock tick(时钟计时单元) .概念 在C/C++中,对字符串的操作有很多值得注意的问题,同样,C ...
- time_t和struct tm之间的转换
time_t到struct tm的转换: #include <time.h> struct tm *localtime(const time_t *timep); struct tm到ti ...
- 将日期和时间作为 struct tm型的值直接向二进制文件进行读写
#include <stdio.h> #include <time.h> char data_file[]="D:\\%\\datetime.dat"; v ...
- 时间操作(struct tm、time_t)求指定日期 前n天的日期
1.在标准C/C++中,我们可通过tm结构来获得日期和时间,tm结构在time.h中的定义如下: #ifndef _TM_DEFINED struct tm { int tm_sec; /* 秒–取值 ...
- struct tm
struct tm { int tm_sec; /* 秒–取值区间为[0,59] */ int tm_min; /* 分 - 取值区间为[0,59] */ int tm_hour; /* 时 - 取值 ...
- localtime和localtime_r
上程序: #include <cstdlib> #include <iostream> #include <time.h> #include <stdio.h ...
- C语言中tm结构体
struct tm { int tm_sec; /* Seconds. [0-60] (1 leap second) */ int tm_min; /* Minutes. [0-59] */ int ...
随机推荐
- 转:SetWindowText 的用法
SetWindowText 函数功能:该函数改变指定窗口的标题栏的文本内容(如果窗口有标题栏).如果指定窗口是一个控件,则改变控件的文本内容.然而,SetWindowText函数不改变其他应用程序 ...
- TOP 100 MISSPELT/MISSPELLED WORDS IN ENGLISH
acceptable accidentally accommodate acquire acquit a lot amateur apparent argument atheist believe ...
- PHP 类中的常量
类中的常量与静态成员类似他们只属于类而不属于类的任何实例,访问形式与访问静态成员一样. 例如: <?php class MyConst{ const RED="Red"; c ...
- SQL通过xml插入批量数据
存储过程: CREATE PROCEDURE [dbo].[UP_PurchasexxxCard] @OrderInfo XMLASBEGIN SET NOCOUNT ON; DECLARE @Dat ...
- 利用http实现文件的上传和下载
其他语言都比较方便,使用http上传.但是C++这样就差点,不过还好,Linux下有个curl的命令行工具,这是一个开源项目,底下有个子项目是libcurl,curl就是调用这个API实现的一系列ft ...
- Android添加标题进度条
requestWindowFeaure(Window.FEATURE_PROGRESS); setProgressBarVisibility(true); 这两步必须在setContentView() ...
- word-wrap: break-word 和 word-break: break-all 到底有啥区别?
做项目改bug的时候,遇到过好多次,要么是文本超出文本区域,或者单词太长(一般是url链接中的一些鬼),把装它的标签强制撑大,导致一些响应式问题.除此之外,还有很多问题,每次都是恍然醒悟,然后又在网上 ...
- 2016-05-I
2016 年上半年软件设计师上午真题 1. VLIW 是( )的简称.A.复杂指令系统计算机 B.超大规模集成电路C.单指令流多数据流 D.超长指令字 2.主存与 Cache 的地址映射方式中,( ) ...
- Intellj Idea 2016.1.3的使用
Intellj Idea 2016.1.3的使用:http://blog.csdn.net/bleachswh/article/details/51811055 极客学院教程:http://wiki. ...
- hibernate jpa 注解 @Temporal(TemporalType.DATE) 格式化时间日期,页面直接得到格式化类型的值
1.日期: @Temporal(TemporalType.DATE) @Column(name = "applyDate", nullable = false, length = ...