time_t time(time_t *tloc);

功能:获取纪元1970-01-01 00:00:00以来所经历的秒数

参数:

tloc:用来存储返回时间

返回值:成功:返回秒数, 失败:-1

-------------------------------------------------------------------------------------------------------

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

struct tm {
int tm_sec; /* Seconds (0-60) */
int tm_min; /* Minutes (0-59) */
int tm_hour; /* Hours (0-23) */
int tm_mday; /* Day of the month (1-31) */
int tm_mon; /* Month (0-11) */
int tm_year; /* Year - 1900 */
int tm_wday; /* Day of the week (0-6, Sunday = 0) */
int tm_yday; /* Day in the year (0-365, 1 Jan = 0) */
int tm_isdst; /* Daylight saving time */
};

---------------------------------------------------------------------------------------------------

#include <stdio.h>
#include <time.h>

int main()
{
time_t stim;
time(&stim);
struct tm *stm, *stm2;
stm = localtime(&stim);
printf("%04d-%02d-%02d %02d:%02d:%02d\n", stm->tm_year + 1900, \
stm->tm_mon + 1, stm->tm_mday, stm->tm_hour, stm->tm_min,\
stm->tm_sec);
stm2 = localtime_r(&stim, stm2);
printf("%04d-%02d-%02d %02d:%02d:%02d\n", stm2->tm_year + 1900, \
stm2->tm_mon + 1, stm2->tm_mday, stm2->tm_hour, stm2->tm_min,\
stm2->tm_sec);
return 0;
}
---------------------------------------------------------------------------------------------------------

最新文章

  1. &lt;&lt;&lt; chm格式文件打不开及一些问题
  2. Invert Binary Tree
  3. jQuery的eq方法
  4. 最短的可通过编译的C语言程序
  5. Python 脚本 监控数据库状态
  6. [转]50 Shades of Go: Traps, Gotchas, and Common Mistakes for New Golang Devs
  7. 什么时候该使用NoSQL存储数据库?
  8. python 32位、64位确定
  9. shell检测interface是否已分配ip,qt调用shell脚本
  10. first-,second- and third-class value
  11. linux sort 用法
  12. String Matching Content Length
  13. [原创]ASM动态修改JAVA函数之函数字节码初探
  14. .NET Core微服务之服务间的调用方式(REST and RPC)
  15. MySQL 笔记整理(14) --count(*)这么慢,我该怎么办?
  16. GBDT总结
  17. Java中如何设置表格处于不可编辑状态
  18. Python基础01_介绍_HelloWorld
  19. leetcode 730 Count Different Palindromic Subsequences
  20. 手动下载python更新后 换回以前版本

热门文章

  1. javascript原生知识点
  2. 【ABAP系列】SAP Smartforms 设置纸张打印格式
  3. PJzhang:任意密码重置的常规姿势
  4. 维特比算法及python实现
  5. hadoop的目录结构介绍
  6. delete an extra edge from BST
  7. Shell初学(七)linux账户管理/群组管理
  8. js执行多次事件,而非一次
  9. spark教程(三)-RDD认知与创建
  10. Codeforces 1229C. Konrad and Company Evaluation