C++ 时间戳转为本地时间函数
发布时间
阅读量:
阅读量
为将时间戳转换为本地时间,花费了整个上午的时间在网络上查找资料,直至中午才研究出一种可行的方法,并在此基础上进行了一些优化调整。
.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
全部评论 (0)
还没有任何评论哟~
