C语言获取当前时间
#include <stdio.h>
#include <time.h> void main ()
{
time_t rawtime;
struct tm * timeinfo; time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( "\007The current date/time is: %s", asctime (timeinfo) ); exit();
} =================
#include <time.h> -- 必须时间函数头文件
time_t -- 时间类型(time.h 定义)
struct tm -- 时间结构time.h 定义下:
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst; time ( &rawtime ); -- 获取时间秒计从1970年1月日起算存于rawtime
localtime ( &rawtime ); -- 转当地时间tm 时间结构
asctime ()-- 转标准ASCII时间格式:
星期 月 日 时:分:秒 年
=========================================
要格式样输出:
printf ( "%4d-%02d-%02d %02d:%02d:%02d\n",+timeinfo->tm_year, +timeinfo->tm_mon,
timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); 直接打印tmtm_year 从1900年计算所要加1900
月tm_mon从0计算所要加1 输出到某个字符串:
//获取当地时间
char now_date[16]={'\0'};
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
snprintf(now_date,16,"%04d-%02d-%02d",(1900+timeinfo->tm_year),(1+timeinfo->tm_mon),
timeinfo->tm_mday);
printf("Current date:%s\n",now_date);
C语言获取当前时间的更多相关文章
- C语言获取系统时间的几种方式[转]
C语言获取系统时间的几种方式 C语言中如何获取时间?精度如何? 1 使用time_t time( time_t * timer ) 精确到秒 2 使用clock_t clock() 得到的是CPU时间 ...
- C语言获取系统时间的几种方式
C语言获取系统时间的几种方式 2009-07-22 11:18:50| 分类: 编程学习 |字号 订阅 C语言中如何获取时间?精度如何? 1 使用time_t time( time_t * ...
- C语言获取系统时间的函数
在标准C编程中,我们如何写程序来获取当前系统的时间呢? 获取系统时间的函数 #include <time.h> time_t time(time_t *t) 参数:如果参数不为空,那么 ...
- linux下c语言获取当前时间
和时间有关的函数定义在头文件”time.h”中 常用函数: time_t time(time_t *t); 函数说明:此函数会返回从公元 1970 年1 月1 日的UTC 时间从0 时0 分0 秒算起 ...
- C语言获取系统时间
localtime函数 #include <stdio.h> #include <time.h> int main () { time_t t; struct tm *lt; ...
- c语言获取系统时间并格式化
// #include <time.h> int GetAndFormatSystemTime(char* timeBuff) { if (timeBuff == NULL) { retu ...
- C语言获取时间
转载:http://www.cnblogs.com/fzhe/archive/2012/11/06/2757858.html C语言获取系统时间的几种方式 C语言中如何获取时间?精度如何? 1 使 ...
- C语言获取系统当前时间
C语言获取系统当前时间 time_t -- 时间类型 struct tm -- 时间结构 time(&now)函数获取当前时间距1970年1月1日的秒数,以秒计数单位. localtime ( ...
- linux下C语言获取微秒级时间
使用C语言在linux环境下获得微秒级时间 1.数据结构 int gettimeofday(struct timeval*tv, struct timezone *tz); 其参数tv是保存获取时间结 ...
随机推荐
- 19.go语言基础学习(下)——2019年12月16日
2019年12月16日16:57:04 5.接口 2019年11月01日15:56:09 5.1 duck typing 1. 2. 接口 3.介绍 Go 语言的接口设计是非侵入式的,接口编写者无须知 ...
- D0g3_Trash_Pwn_Writeup
Trash Pwn 下载文件 1 首先使用checksec查看有什么保护 可以发现,有canary保护(Stack),堆栈不可执行(NX),地址随机化没有开启(PIE) 2 使用IDA打开看看 mai ...
- 洛谷 P1407 稳定婚姻
问题描述 我国的离婚率连续7年上升,今年的头两季,平均每天有近5000对夫妇离婚,大城市的离婚率上升最快,有研究婚姻问题的专家认为,是与简化离婚手续有关.25岁的姗姗和男友谈恋爱半年就结婚,结婚不到两 ...
- 【leetcode】1038. Binary Search Tree to Greater Sum Tree
题目如下: Given the root of a binary search tree with distinct values, modify it so that every node has ...
- Task5.NB_SVM_LDA
参考:https://blog.csdn.net/u013710265/article/details/72780520 贝叶斯公式就一行: P(Y|X)=P(X|Y)P(Y)P(X) 而它其实是由以 ...
- TreeMap定制排序和自然排序
TreeMap定制排序和自然排序自然排序是实现Comparable接口的方法.代码如下: @Override public int compareTo(Object o) { if (o instan ...
- 微信公众号号开发(Java)
参考:http://www.cnblogs.com/fengzheng/p/5023678.html http://www.cnblogs.com/xdp-gacl/p/5151857.html 一: ...
- PB TB级数据
Byte.KB.MB.GB.TB.PB.EB.ZB.YB. 1KB=1000B1MB=1000KB1GB=1000MB1TB=1000GB 1TB=240B=1024MB 1PB=250B k M G ...
- html、css、js分工,内核,html头,html表单
html:内容css:样式js:交互 内核 浏览器控制台输入navigator.userAgent,回车显示出内核"Mozilla/5.0 (Windows NT 6.1; WOW64) A ...
- Flask学习 2修改路由规则 传入参数访问url
#!/usr/bin/env python # encoding: utf-8 """ @version: v1.0 @author: cxa @file: flask0 ...