我正在使用HighStock图表link
它使用来自api apilink
的数据第一个参数是日期,如
[
/* Sep 2009 */
[1252368000000,24.70],
..
]
这个日期格式是什么?如何获得这种格式是C#?
答案 0 :(得分:3)
这似乎是JavaScript date value,以1970年1月1日以来的毫秒数为单位提供。
您可以将其转换为DateTime
several ways in C#。
例如(从上面的链接),您可以添加自JavaScript纪元以来经过的刻度。要从毫秒转换为刻度,请乘以10,000。因此,您可以写下以下内容:
new DateTime(1970, 1, 1).AddTicks(1252368000000 * 10000);
答案 1 :(得分:1)
/// <summary>
/// Dates represented as Unix timestamp
/// with slight modification: it defined as the number
/// of seconds that have elapsed since 00:00:00, Thursday, 1 January 1970.
/// To convert it to .NET DateTime use following extension
/// </summary>
/// <param name="_time">DateTime</param>
/// <returns>Return as DateTime of uint time
/// </returns>
public DateTime ToDateTime( uint _time)
{
return new DateTime(1970, 1, 1).AddSeconds(_time);
}
/// <summary>
/// Dates represented as Unix timestamp
/// with slight modification: it defined as the number
/// of seconds that have elapsed since 00:00:00 Thursday, 1 January 1970.
/// To convert .NET DateTime to Unix time use following extension
/// </summary>
/// <param name="_time">DateTime</param>
/// <returns>
/// Return as uint time of DateTime
/// </returns>
public uint ToUnixTime(DateTime _time)
{
return (uint)_time.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
}