【发布时间】:2011-01-22 17:48:52
【问题描述】:
您好,我无法以这种格式解析日期:
1295716379
我不知道是什么日期格式。
此字符串的人类可读值为:
22. 1. 2011, 18.12
我也不知道这种格式是牛仔编码器格式还是一些“标准”。
如果可以将顶部的字符串解析为人类可读的格式,例如 C#、Java、C++。
谢谢
【问题讨论】:
您好,我无法以这种格式解析日期:
1295716379
我不知道是什么日期格式。
此字符串的人类可读值为:
22. 1. 2011, 18.12
我也不知道这种格式是牛仔编码器格式还是一些“标准”。
如果可以将顶部的字符串解析为人类可读的格式,例如 C#、Java、C++。
谢谢
【问题讨论】:
看起来像unix timestamp。
你可以像这样解析它们:
更多链接:Epoch Converter.com.
【讨论】:
这是一个 UNIX 纪元时间戳。
在 C# 中将其转换为 DateTime 的示例:
DateTime ToDateTime(int seconds)
{
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
return epoch.ToLocalTime().AddSeconds(seconds);
}
这会将其转换为当地时间。
【讨论】:
已验证,是unix时间戳。
时间是Sat Jan 22 17:12:59 2011 UTC。
看起来你有一个本地时间值,你的时区是 UTC+1。
在 C/C++ 中:
#define _USE_32BIT_TIME_T
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
int i = atoi("1295716379");
time_t t = (time_t)i;
puts(ctime( &t ));
tm t_tm = *gmtime(&t);
puts(asctime( &t_tm ));
return 0;
}
输出:
Sun Jan 23 02:12:59 2011
Sat Jan 22 17:12:59 2011
注意gmtime返回UTC时间值,localtime返回本地时间值。
PS:我生活在 UTC+9 时区
【讨论】: