如何把服务器提供的时间 转换成本地时间

cqcwasd 2010-08-26 11:41:46
我是通过ping的icmp协议 type=13获得服务器的时间 服务器传回的时间是“13053510” 这个数字,
想请问下如何把这个数字转换成本地时间,这个时间应该在11点35-40 左右的时间,请高手帮忙,
...全文
251 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
cqcwasd 2010-08-26
  • 打赏
  • 举报
回复
http://blog.csdn.net/cqcwasd/archive/2010/08/24/5835938.aspx
帮忙看下 因为这个时间好像是 格林尼治时间 不明白这个时间要怎么转换
dimple0513 2010-08-26
  • 打赏
  • 举报
回复
是CTime的对象么,如果是的话,只要用
CString sVal = tm.Format(L"%Y-%m-%d %H:%M:%S");
就能得到 tm的值了。
PS: tm 是CTime对象

我试了一下
CTime tm(13053510);
好像时间不是你说的那个.
而是 1970-06-01 09:58:30
woshuo12005 2010-08-26
  • 打赏
  • 举报
回复
年+1900
。。。
woshuo12005 2010-08-26
  • 打赏
  • 举报
回复
年+1970
月+1
  • 打赏
  • 举报
回复
http://blog.chinaunix.net/u1/50685/showart_437316.html

具体用法自己看吧。

time_t
tm
和自己指定时间格式间转换。
  • 打赏
  • 举报
回复

time_t M_idata = 13053510;
char sDate[256] ;
struct tm *t_time;


t_time = localtime(&M_idata);
strftime(sDate,256,"%Y-%m-%d ",t_time);
cout<<sDate<<endl;

mymtom 2010-08-26
  • 打赏
  • 举报
回复
取出当前日期,算出时间,组合在一起就可以了!

/**
* Copyright (C), 1988-2010
*
* $Id$
*
* $Log$
*/
#ifndef lint
static const char RCSID[] =
"$Id$";
static const char RELID[] =
"$" "Date: "__FILE__" "__DATE__" "__TIME__" $";
#endif /* not lint */

/**
* @file icmptime.c
* @brief
*/

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

void icmptime(time_t ms)
{
time_t s, m;
struct tm d;
struct tm t;
char buf[24];

/* 日期部分 */
s = time(0);
d = *localtime(&s);

/* 秒 */
s = ms / 1000;
/* 毫秒 */
m = ms % 1000;
/* 时间部分 */
t = *localtime(&s);

/* 时间日期组合 */
d.tm_hour = t.tm_hour;
d.tm_min = t.tm_min;
d.tm_sec = t.tm_sec;

strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &d);
sprintf(buf + 19, ".%03d", (int)m);
printf("%s\n", buf);
}

int
main(int argc, char *argv[])
{

icmptime(13053510);
return 0;
}

64,674

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧