admin管理员组文章数量:1313799
I'm having a hard time getting Google Charts to understand the datetime format. I used an example [1] where the datetime format is set to a simple month day and year, but I changed it to take an input of type datetime. An example is available the following page:
.php
The start of the code is as follows:
data.addColumn('datetime', 'Date');
data.addColumn('number', 'Active or not');
data.addRows(1768);
data.setValue(0, 0, new Date(1306192258));
data.setValue(0, 1, 1);
Why will Google change that Date format to Jan 15, 1970? (Start of Epoch time?)
Thanks!
[1]
I'm having a hard time getting Google Charts to understand the datetime format. I used an example [1] where the datetime format is set to a simple month day and year, but I changed it to take an input of type datetime. An example is available the following page:
http://www.sccs.swarthmore.edu/users/09/leo/cgi-bin/viewer.php
The start of the code is as follows:
data.addColumn('datetime', 'Date');
data.addColumn('number', 'Active or not');
data.addRows(1768);
data.setValue(0, 0, new Date(1306192258));
data.setValue(0, 1, 1);
Why will Google change that Date format to Jan 15, 1970? (Start of Epoch time?)
Thanks!
[1] http://www.beakkon./geek/how-to/create-interactive-charts-using-google-charts-api
Share Improve this question asked May 27, 2011 at 22:15 RioRio 14.9k22 gold badges71 silver badges109 bronze badges2 Answers
Reset to default 5Try this:
data.addColumn('datetime', 'Date');
data.addColumn('number', 'Active or not');
data.addRows(1768);
var d = new Date();
d.setTime(1306192258*1000);
data.setValue(0, 0, d);
data.setValue(0, 1, 1);
Some more info on the Javascript Date function can be found w3schools. website I found - new Date("July 21, 2011 02:00:00") to be a good promise for what I wanted to do.
Snippet of my code
data.addRows([
[new Date("July 21, 2011 00:00:00"), 0.319636363636 ],
[new Date("July 21, 2011 07:00:00"), 0.319636363636 ],
[new Date("July 21, 2011 22:00:00"), 0.319636363636 ],
[new Date("July 21, 2011 23:00:00"), 0.319636363636 ],
[new Date("July 22, 2011 09:00:00"), 0.319636363636 ],
[new Date("July 22, 2011 10:00:00"), 0.319636363636 ]
]);
本文标签: javascriptGoogle Charts API datetime unix formatStack Overflow
版权声明:本文标题:javascript - Google Charts API datetime unix format? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741923113a2405123.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论