格式化时间 与 时间戳的转换
2015-08-06 19:38
281 查看
2015-08-06 19:37:58
/*! * <格式化时间与时间戳的转换> * * 2015/08/06 by <felove> */ #include <stdio.h> #include <windows.h> #include <time.h> void timestampToFormat(time_t& t_1, tm& tm_1); time_t formatToTimestamp(int _nYear, int _nMonth, int _nDay, int _nHour, int _nMinute, int _nSecond); int main() { //时间戳转格式化时间 time_t timep; time(&timep); struct tm tm_1; timestampToFormat(timep,tm_1); printf("time():%d\n",timep); printf("[%04d-%02d-%02d][%02d:%02d:%02d]\n",tm_1.tm_year + 1900,tm_1.tm_mon + 1,tm_1.tm_mday,tm_1.tm_hour,tm_1.tm_min,tm_1.tm_sec); //格式化时间转时间戳 time_t timep1 = formatToTimestamp(2015,8,6,18,6,0); printf("time()->localtime()->mktime():%d\n",timep1); system("pause"); return 0; } void timestampToFormat(time_t& t_1, tm& tm_1) { localtime_s(&tm_1,&t_1); } time_t formatToTimestamp(int _nYear, int _nMonth, int _nDay, int _nHour, int _nMinute, int _nSecond) { struct tm tm_1; tm_1.tm_year = _nYear - 1900; tm_1.tm_mon = _nMonth - 1; tm_1.tm_mday = _nDay; tm_1.tm_hour = _nHour; tm_1.tm_min = _nMinute; tm_1.tm_sec = _nSecond; tm_1.tm_isdst = -1; time_t timep1 = mktime(&tm_1); return timep1; }
相关文章推荐
- TCP即时小通信
- JDK1.7的新特性
- leetcode_Delete Node in a Linked List
- Linux - vim按键说明
- Linux - vim按键说明
- Android aidl Binder框架浅析
- php能把函数名作为参数传递吗?
- Emberjs 分页
- iOS 第四课 倒计时 设置文本框的删除键
- Dijkstra's shortest path algorithm
- Java之正则表达式【实例解析】
- Crypto++库在VS 2013中的使用 + 基于操作模式AES加密
- ajax跨域请求数据
- PySe-003-Se-WebDriver 启动浏览器之一 - Firefox
- python实现二维数组
- 虚拟机的网络配置
- iOS让程序延迟执行
- 通用的Adapter
- Java之正则表达式【使用语法】
- TCP连接端口的状态