如何将MySQL datetime值转换为google chart api datetime [英] How to convert MySQL datetime value to google chart api datetime

查看:194
本文介绍了如何将MySQL datetime值转换为google chart api datetime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将MySQL数据库中的datetime字段的值转换为可传递给Google chart datetime字段的值。

I am trying to convert a value from a datetime field in a MySQL database to a value I can pass on to a Google chart datetime field.

例如MySQL值: 2012-03-05 17:03:56

Google Chart Api链接: http://code.google.com/apis/chart/interactive/docs/ gallery / linechart.html

Google Chart Api link: http://code.google.com/apis/chart/interactive/docs/gallery/linechart.html

我想将其传递给定义如下的列: data.addColumn('datetime', 't');

I want to pass this into a column defined like this: data.addColumn('datetime', 't');

我想将它发送到这样一行: data.addRow([date_value ]);

I want to send it into a row as such: data.addRow([date_value]);

我不知道如何在两者之间进行转换。所以我要求的是如何将MySQL datetime值转换为google图表api datetime值?

I'm not sure how to convert between the two. So what I am asking is How do I convert MySQL datetime value to a google chart api datetime value?

推荐答案

Google只是使用标准的JavaScript Date对象。更简单的方法是从MySQL中获取一个 unix_timestamp(yourdatefield),这样可以让你从秒开始。

Google's just using the standard javascript Date object. Easier method would be to get a unix_timestamp(yourdatefield) out of MySQL, which gives you seconds-since-the-epoch.

Javascript的date对象接受一个initializer值的毫秒,因为:

Javascript's date object accepts milliseconds-since-the-epoch as one initializer value, so:

data.addRow(new Date(<?php echo ($seconds_from_db) ?>000));
                                                     ^^^--- 3 extra zeroes to make it a millisecond value

这篇关于如何将MySQL datetime值转换为google chart api datetime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆