【发布时间】:2017-01-13 09:34:15
【问题描述】:
我正在使用 HighStock 图表 link
它使用来自 api apilink 的数据
第一个参数是日期
[
/* Sep 2009 */
[1252368000000,24.70],
..
]
这个日期格式是什么?怎么得到这个格式是C#?
【问题讨论】:
标签: c# asp.net json highcharts
我正在使用 HighStock 图表 link
它使用来自 api apilink 的数据
第一个参数是日期
[
/* Sep 2009 */
[1252368000000,24.70],
..
]
这个日期格式是什么?怎么得到这个格式是C#?
【问题讨论】:
标签: c# asp.net json highcharts
这似乎是一个JavaScript date value,以自 1970 年 1 月 1 日以来经过的毫秒数提供。
您可以将其转换为DateTime several ways in C#。
例如(来自上面的链接),您可以添加自 JavaScript 纪元以来经过的刻度。要将毫秒转换为刻度,请乘以 10,000。因此,您可以编写以下内容:
new DateTime(1970, 1, 1).AddTicks(1252368000000 * 10000);
【讨论】:
/// <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;
}
【讨论】: