我正在尝试将System的当前日期和时间转换为整数值,然后将其添加到List中。
该代码是
List<int> _data = new List<int>();
foreach (DataRow row in dt.Rows)
{
_data.Add((int)Convert.ToInt32(DateTime.Now.ToLocalTime()));
_data.Add((int)Convert.ToInt32(row["S11"]));
}
JavaScriptSerializer jss = new JavaScriptSerializer();
chartData = jss.Serialize(_data);
Response.Write(chartData);
我收到错误提示 Invalid cast from "DateTime' to 'Int32'
我想以这种形式进行转换以使json看起来像[1386216561000,74]
这里第一个成员是整数格式的时间,第二个是来自的数据sql server
。
实际上,我要尝试执行的操作与此php
代码相似。该代码是
<?php
// Set the JSON header
header("Content-type: text/json");
$x = time() * 1000;
// The y value is a random number
$y = rand(0, 100);
// Create a PHP array and echo it as JSON
$ret = array($x, $y);
echo json_encode($ret);
?>
您需要将时间转换为纪元时间或某个参考点的某个时间跨度值。
以下是计算时期的代码:
var timeDiff=DateTime.UtcNow - new DateTime(1970, 1, 1);
var totaltime = timeDiff.TotalMilliseconds;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句