下面是C语言的获取本地时间和构造时间进行格式化时间显示输出的相关函数:

This page is part of release 3.35 of the Linux man-pages project.

#include

char *asctime(const struct tm *tm);

char *asctime_r(const struct tm *tm, char *buf);

char *ctime(const time_t *timep);

char *ctime_r(const time_t *timep, char *buf);

struct tm *gmtime(const time_t *timep);

struct tm *gmtime_r(const time_t *timep, struct tm *result);

struct tm *localtime(const time_t *timep);

struct tm *localtime_r(const time_t *timep, struct tm *result);

time_t mktime(struct tm *tm);

Broken-down time is stored in the structure tm which is defined in

as follows:

struct tm {

int tm_sec; /* seconds */

int tm_min; /* minutes */

int tm_hour; /* hours */

int tm_mday; /* day of the month */

int tm_mon; /* month */

int tm_year; /* year */

int tm_wday; /* day of the week */

int tm_yday; /* day in the year */

int tm_isdst; /* daylight saving time */

};

The members of the tm structure are:

tm_sec The number of seconds after the minute, normally in the range

0 to 59, but can be up to 60 to allow for leap seconds.

tm_min The number of minutes after the hour, in the range 0 to 59.

tm_hour The number of hours past midnight, in the range 0 to 23.

tm_mday The day of the month, in the range 1 to 31.

tm_mon The number of months since January, in the range 0 to 11.

tm_year The number of years since 1900.

tm_wday The number of days since Sunday, in the range 0 to 6.

tm_yday The number of days since January 1, in the range 0 to 365.

tm_isdst A flag that indicates whether daylight saving time is in

effect at the time described. The value is positive if day‐

light saving time is in effect, zero if it is not, and nega‐

tive if the information is not available.

下面是一个程序,输入某个日期(年份不要太久远,否则超出time_t的范围),输出哪个日期是星期几,还有下个星期一是哪天:

#include

#include

#include

using namespace std;

struct Date{

int day;

int month;

int year;

};

Date& add(Date& date,int day,int month,int year){

//这个函数什么也没考虑,仅仅为了测试

date.day+=day;

date.month+=month;

date.year+=year;

return date;

}

int tellWeekday(int mon,int day,int year){

struct tm ct;

//bzero(&ct,sizeof(ct));

memset(&ct,,sizeof(ct));//take care of pointer

ct.tm_year=year-;//maybe ct->tm_year is read only if ct is pointer

ct.tm_mon=mon-;

ct.tm_mday=day;

//ct.tm_sec=ct->tm_min=ct->tm_hour=ct->tm_wday=ct->tm_yday=ct->tm_isdst=0;

time_t ctt=mktime(&ct);

if(ctt==-) return -;

struct tm* ans=localtime(&ctt);

cout<tm_wday<

}

int nextMondayDate(int mon,int day,int year){

struct tm ct;

int delta;

//bzero(&ct,sizeof(ct));

memset(&ct,,sizeof(ct));

ct.tm_year=year-;

ct.tm_mon=mon-;

ct.tm_mday=day;

time_t ctt=mktime(&ct);

if(ctt==-) return -;

struct tm* tm2=localtime(&ctt);

if(tm2->tm_wday==) delta=;

else delta=-tm2->tm_wday;

ctt+=delta**;

tm2=localtime(&ctt);

cout<tm_mon+<tm_mday<tm_year+<

}

int main(){

Date today,otherDay;

int mm,dd,yy;

time_t rawTime,inTime;

struct tm* timeInfo;

time(&rawTime);//get secs from 1970.1.1,save to rawTime

timeInfo=localtime(&rawTime);

cout<

today.year=timeInfo->tm_year+;

today.month=timeInfo->tm_mon+;//starts from 0

today.day=timeInfo->tm_mday;

otherDay=add(today,,,);

cout<

<

<

cout<

cin>>mm>>dd>>yy;

tellWeekday(mm,dd,yy);

cout<

cin>>mm>>dd>>yy;

nextMondayDate(mm,dd,yy);

system("pause");

return ;

}

常用C语言time时间函数

常见的时间函数有time( ).ctime( ).gmtime( ).localtime( ).mktime( ).asctime( ).difftime( ).gettimeofday( ).set ...

c语言随机函数&amp&semi;&amp&semi;时间函数

c语言中的随机函数为rand(),但是rand生成的值得大小主要相对一个变量才产生的一定有含义的数,这个相对的变量我们可以再srand()函数中进行设置,srand函数是void类型,内部含一个无符号 ...

R语言日期时间函数

Sys.Date( ) returns today's date. date() returns the current date and time.# print today's datetoday ...

C语言 常用的时间函数

//时间函数的使用 #define _CRT_SECURE_NO_WARNINGS #include #include #include& ...

Loadrunner时间函数、用时间生成订单编号例子

Loadrunner中取时间函数.用时间函数生成订单编号例子: 问题的提出: (1)有时候在Loadrunner中用C语言设计脚本 ...

Oracle日期时间函数大全

ORACLE日期时间函数大全 TO_DATE格式(以时间:2007-11-02 13:45:25为例) Year: yy two digits 两位年 显示值:07 yyy three digits ...

Linux时间函数之gettimeofday&lpar;&rpar;函数之使用方法

1.简介: 在C语言中可以使用函数gettimeofday()函数来得到时间.它的精度可以达到微妙 2.函数原型: #include int gettimeofda ...

php时间函数整理

PHP中的时间函数有这么些:(1)date用法: date(格式,[时间]);如果没有时间参数,则使用当前时间. 格式是一个字符串,其中以下字符有特殊意义:U 替换成从一个起始时间(好象是1970年1 ...

随机推荐

Hibernate组件映射

Hibernate联合主键映射以及组件映射 在Hibernate中联合主键的形成有两种可能:一种是由多对多映射形成的,多对多映射会形成第三张表,一般来说第三张表的主键是由其他两张表的主键构成的(比如学 ...

【Alpha】Daily Scrum Meeting第五次

一.本次Daily Scrum Meeting主要内容 每个人学习情况 任务安排 界面设计问题,怎样让界面更好看? 二.任务安排 学号尾数 昨天做的任务 今天的任务 明天的任务 612 时间轴控件优化 ...

Excel&colon; Switch &lpar;transpose&rpar; columns and rows

链接:https://support.office.com/en-in/article/Switch-transpose-columns-and-rows-ed1215f5-59af-47e6-953 ...

EasyPusher推流服务接口的&period;NET导出

本文是在使用由 EasyDarwin 团队开发的EasyPusher时导出的C++接口的.NET实现 public class EasyPushSDK { public EasyPushSDK() { ...

【linux操作命令】mysql

1.linux下启动mysql的命令: mysqladmin start /ect/init.d/mysql start (前面为mysql的安装路径) 2.linux下重启mysql的命令: mys ...

X86在逻辑地址、线性地址、理解虚拟地址和物理地址

参考:http://bbs.chinaunix.net/thread-2083672-1-1.html 本贴涉及的硬件平台是X86.假设是其他平台,不保证能一一对号入座.可是举一反三,我想是全然可行的 ...

Git拉取、提交、迁出、合并、删除分之命令

#拉取代码 git clone -b 分之名称 git地址 #提交代码 git add . //:注释,if是第一次提交: $ git add --all . (请注意后面有个英文点(表示是当前目录) ...

PHP把采集抓取网页的html中的的&amp&semi;nbsp&semi;去掉或者分割成数组

日期:2017/11/6 操作系统:windows 今天抓取网页的时候出现 无法替换,经过多次测试,找到了办法;(注意是从网页上抓取到的) 分割 explode("  ",HTML ...

AtCoder &vert; ARC102 &vert; 瞎讲报告

目录 ARC102 前言 正文 传送链接~ ARC102 前言 实在是太菜了....写完第一题就弃疗..感觉T3好歹也是道可做题吧!!然后T2怎么又是进制拆分! 正文 A 题意 给你两个数字\(n,k ...

Centos之命令搜索命令whereis与which

Centos之命令搜索命令whereis与which whereis 命令名 #搜索命令所在路径及帮助文档所在位置 选项: -b :只查找可执行文件位置 -m:只查找帮助文件 [root@localh ...

c语言时间函数状态,C语言的时间函数相关推荐

  1. R语言sys方法:sys.chmod函数改变指定文件的权限、Sys.Date函数返回系统的当前日期、Sys.time函数返回系统的当前时间

    R语言sys方法:sys.chmod函数改变指定文件的权限.Sys.Date函数返回系统的当前日期.Sys.time函数返回系统的当前时间 目录

  2. c语言 获取文件修改时间,C语言中用于修改文件的存取时间的函数使用

    C语言utime()函数:修改文件的存取时间和更改时间头文件: #include #include 定义函数: int utime(const char * filename, struct utim ...

  3. R语言使用strptime函数把字符串转化为时间对象、使用strftime函数把时间对象转化为字符串实战:指定时区、包含时间、分钟、秒、微妙

    R语言使用strptime函数把字符串转化为时间对象.使用strftime函数把时间对象转化为字符串实战:指定时区.包含时间.分钟.秒.微妙 目录

  4. c语言如何让函数一直执行,C语言如何实现在每天某个特定时间执行某个函数?

    慕仙森 Windows提供了定时器,帮助编写定期发送消息的程序.定时器一般通过一下两中方式通知应用程序间隔时间已到.⑴ 给指定窗口发送WM_TIMER消息,也就是下面的给出在窗口类中使用的方法.⑵ 调 ...

  5. MT4/MQL4入门到精通EA教程第八课-MQL语言常用函数(八)-常用时间功能函数

    时间功能函数详解 TimeCurrent(); //返回服务器当前时间 TimeDayOfWeek();//返回当前时间星期几 TimeGMT(); //返回GTM时间 TimeGMTOffset() ...

  6. 用 C 语言开发一门编程语言 — 基于 Lambda 表达式的函数设计

    目录 文章目录 目录 前文列表 函数 Lambda 表达式 函数设计 函数的存储 实现 Lambda 函数 函数的运行环境 函数调用 可变长的函数参数 源代码 前文列表 <用 C 语言开发一门编 ...

  7. 《Go语言圣经》学习笔记 第五章函数

    <Go语言圣经>学习笔记 第五章 函数 目录 函数声明 递归 多返回值 匿名函数 可变参数 Deferred函数 Panic异常 Recover捕获异常 注:学习<Go语言圣经> ...

  8. main在c语言中的作用,main函数在C语言中是怎么定义的?有什么作用?

    main函数在C语言中是怎么定义的?有什么作用? 更新时间:2019-10-24 13:55 最满意答案 额,main不是程序的最开始啦.拿用glibc的程序来说,C语言执行的过程应该是 _start ...

  9. C语言semaphore头文件,C语言再学习 -- 常用头文件和函数

    Linux常用头文件如下: POSIX标准定义的头文件 < dirent.h>        目录项 < fcntl.h>         文件控制 < fnmatch. ...

最新文章

  1. php里面的log是什么文件夹,用PHP生成自己的LOG文件
  2. npm install --save和npm install --save-dev的区别
  3. 更新yum源并重建缓存
  4. 动态规划经典算法--最大子段和
  5. python map lambda 分割字符串_python六剑客:map()、lambda()、filter()、reduce()、推导类表、切片...
  6. 双极型三极管共集电极、共基极放大电路
  7. 看完这篇你们团队的代码也很规范
  8. 清华 | 量化卷积神经网络加速芯片
  9. (130)FPGA面试题-FPGA设计中波特率和比特率的区别
  10. 前端工程师面试经验导图
  11. BSTR与CString之前的转换
  12. 蓝海灵豚医疗器械管理软件医用耗材专版
  13. Python实现汉字转换拼音
  14. 【原文翻译】深度残差收缩网络 Deep Residual Shrinkage Networks for Fault Diagnosis
  15. 各个国家的人有什么特点?
  16. QT安装我i发下载存档问题解决
  17. SAXReader的主要用法(XML)
  18. 个人项目——中小学数学卷子自动生成程序
  19. [WUSTCTF2020]dp_leaking_1s_very_d@angerous
  20. 谷歌Android无障碍套件,Android无障碍套件

热门文章

  1. 忘记UCENTER创始人密码的解决办法
  2. vivi采集php,php源码:VIVI万能小偷程序1.5 智能采集不求人(内置2条采集规则)
  3. Oracle数据更新,表结构,约束
  4. 软件测试 | 测试开发 | Git实战(四)| Git分支管理实操,在线合并和本地合并
  5. 基于Python的Excel读写操作--内容超详细,值得排排坐
  6. [DOS教程----读书笔记]命令全集
  7. VUE Object.assign()的使用
  8. 【读书笔记】金字塔原理-学习总结
  9. 50M/s, Onedrive直链提取-IDM实现满速下载
  10. 线性代数【初等变换】