获取系统时间
来源:互联网 发布:c语言窗口按键程序 编辑:程序博客网 时间:2024/06/16 03:54
1. 获取当前时间字符串
#include <time.h>
time_t t = time(NULL);
struct tm *tm = localtime(&t);
printf("%4d-%02d-%02d %02d:%02d:%02d\n",
tm->tm_year + 1900, tm->tm_mon + 1,
tm->tm_mday, tm->tm_hour,
tm->tm_min, tm->tm_sec);
2. 字符串转 时间
#include <iostream>
#include <fstream>
#include <time.h>
using namespace std;
int main(int argc, char *argv[]) {
time_t tt = time(NULL);
cout << (long)tt <<endl;
const char*date="2012-02-14 14:00:00"; //这个时间格式 必须与strptime中相同
tm t;
if (strptime(date,"%Y-%m-%d %H:%M:%S",&t)) {
time_t ttt=mktime(&t);
cout <<(long)ttt <<endl;
printf("%d/%d/%d %d:%d:%d\n",t.tm_year+1900,
t.tm_mon+1,t.tm_mday,t.tm_hour, t.tm_min, t.tm_sec);
} else
cout << "strptime error.";
}
- linux时间-获取系统时间
- 获取(设置)系统时间
- jsp获取系统时间
- 获取系统时间
- VC--获取系统时间
- 获取系统时间
- 获取系统当前时间
- 获取系统时间
- 获取当前系统时间
- 获取系统时间
- 获取系统时间
- C++ 获取系统时间
- oracle 获取系统时间
- java获取系统时间
- 获取系统时间代码
- 获取系统时间
- 获取系统时间
- 获取当前系统时间
- JAVA 中URL链接中文参数乱码的处理方法
- oracle 分页查询
- POJ 2912 Rochambeau
- 全兼容可高亮二级缓冲折叠菜单
- 使用LoadRunner上传及下载文件
- 获取系统时间
- Myeclipse 10 for mac 安装过程及myeclipse 10 for mac 破解版下载
- html图标显示
- 使用匿名管道双向通讯的方式,实现pc端和Android端通讯。
- 2013/2/1 工作报告
- BSTR与其它字符串类型转换
- 三维旋转矩阵使用算法
- 重力感应完美修复、akmd_set文件导入教程!
- hive 错误记录