C++ 时间戳转本地时间 函数
C++ 函数 时间 本地
2023-09-14 09:07:02 时间
时间戳转本地时间在网上找了一上午,中午研究出来一个,同时进行了一些改进。
.h文件
//时间戳转本地时间。returnType=0,返回年月日时分秒,returnType=1,返回年月日,returnType=2,返回时分秒。time_t 单位是秒。
std::string TimestampToTimeString(time_t t, int nType=0);
.cpp文件
//时间戳转本地时间。returnType=0,返回年月日时分秒,returnType=1,返回年月日,returnType=2,返回时分秒。time_t 单位是秒。
std::string TimestampToTimeString(time_t t, int nType)
{
t = t + 28800;//偏移八个时区
struct tm *p;
char s[32];
std::string strTime;
p = gmtime(&t);
switch (nType)
{
case 0:
{
strftime(s, 32, "%Y-%m-%d %H:%M:%S", p);
strTime = s;
}
break;
case 1:
{
strftime(s, 32 ,"%Y-%m-%d", p);
strTime = s;
}
break;
case 2:
{
strftime(s, 32, "%H:%M : %S", p);
strTime = s;
}
break;
default:
break;
}
return strTime;
}
相关文章
- [C++]VAssistX函数添加注释功能设置
- 【C/C++学院】(8)全局函数和类成员函数转化/友元/操作符重载
- 【C/C++学院】(4)c++开篇/类和对象/命名空间/类型增强/三目运算符/const专题/引用专题/函数增强
- C++网络编程笔记
- C++ 调用Python脚本
- C++ 是否存在一个在main()主函数之前就执行的函数? 这个可以有!
- C语言/C++基础之雪绒花
- 基于 VC++控制台应用程序:GB28181Test 项目概述
- C++项目链接出错, error LNK2019: 无法解析的外部符号 __imp_xxxx_Allocate,该符号在函数 "xxxx" (xxxx) 中被引用
- atitit.GUI图片非规则按钮跟动态图片切换的实现模式总结java .net c# c++ web html js
- paip. c++ 调用.net dll 最好方式powershell 使用总结.
- [C++ 面试基础知识总结]表达式和函数
- C++数据结构-- 递归 排序
- C++ eof()函数相关应用技巧分享
- Effective C++:条款25:考虑写出一个不抛异常的swap函数
- c++字符串
- C/C++开发,sprintf函数末尾添加‘0‘结束问题
- 在 Visual Studio 中自动创建 C++ 成员函数
- C++11 std::function函数包装器
- 13.IDA-显示正确的函数名称(去掉c++后缀命名)
- 自定义C++ void swap(int& ra, int * pb)函数
- C++、STL标准模板库和泛型编程 ——迭代器、 算法、仿函数(侯捷)
- C++使用技巧(二十五):srand、rand、fill/fill_n、generate/generate_n、count_if搭配使用
- C++使用技巧(十五):类构造函数 与 析构函数