将 SQL 时间值传递给 Javascript?
我正在使用融合图表。我正在尝试将 SQL 数组的元素附加到 Javascript strURL 上,以便它们可以传递到另一个页面。 siteid
和 name 等字段可以很好地传递,但每当我尝试传递时间戳时,它都无法加载图表。我无法完整解释整个事情,因为有太多的部分要写,但如果有人对为什么时间戳不能附加到 strURL 有任何想法,那么我很想知道。
返回值如下所示:2011-12-19 12:00:00
I'm using fusion charts. I'm trying to attach elements of an SQL array onto a Javascript strURL so they can be passed to another page. Fields such as siteid
and name get passed fine but whenever I try to pass over the timestamp it fails to load the graph. I can't explain the whole thing in full as there are too many parts to write about but if anyone has any ideas as to why a timestamp cannot be attached to a strURL then I would love to know.
The returned value looks like: 2011-12-19 12:00:00
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该问题可能是由时间戳的形式引起的。如果它包含未正确编码的特殊字符,那么您就会遇到问题。
从数据库获取 Unix 纪元
您可以通过直接从数据库获取 Unix 纪元时间戳来避免这种情况(例如 MySQL):
并且因为这样的时间戳应该只包含数字,所以您不应该遇到任何关于错误字符的问题。
在 JavaScript 中正确处理 Unix 纪元
在 JavaScript 中处理 Unix 纪元时间戳相当简单:
请参阅 this jsfiddle 以获取证明。
The problem probably is caused by the form of the timestamp. If it contains special characters that are not encoded properly, then you have a problem.
Get Unix epoch from database
You can avoid this by getting Unix epoch timestamp directly from database like that (example for MySQL):
and because such timestamp should only consist of digits, you should not have any problems regarding incorrect characters.
Process Unix epoch in JavaScript correctly
Processing Unix epoch timestamps in JavaScript is rather simple:
See this jsfiddle for a proof.