php - 日期转换似乎损失了一天

标签 php javascript mysql date time

正如标题所说,当我从 mysql 转向 javascript 时,我不断损失一天的时间,但我无法弄清楚。当您插入数据库时​​,您会损失一天(假设我输入 10/14/12,数据库将读取 10/13/12),当我从数据库读取时,我也会损失一天(我获取 10/13)/12,现在显示为 10/12/12)。

这是我的过程:

//date input from jquery ui datepicker       
$('#datepicker'+p).datepicker({numberOfMonths: 3, showButtonPanel: true, dateFormat: "D, d M, yy"});

//date sent to php to upload to mysql so there is a format conversion
$start = date("Y-m-d", strtotime($startdate));

现在开始下载:

 //date taken from mysql no modifications

//date modified to be sent to viewer in a nicer format
var start = $.datepicker.formatDate('D, d M, yy', new Date (item.start));

我的想法:这个问题似乎是双向发生的,我很确定我的 javascript 不是问题,因为只有 php 转换一种方式似乎可以排除这两种情况。这可能是我的 mysql 服务器的问题吗?另请注意,日期在 mysql 中保存为 DATE 类型!

//as requested my sql code
 INSERT INTO classdates (start, end, hours, days, off, notes, type, branch) VALUES(:start, :end, :hours, :days, :off, :notes, :type, :branch)

最佳答案

我发现我的问题是 javascript new Date() 函数。它不仅转换日期,而且还对其进行操作。我必须适应时区的变化。

关于php - 日期转换似乎损失了一天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12879826/

相关文章:

php - PHP解析/语法错误;以及如何解决它们

php - 如何在 cakephp 2.2 中使用 $_SESSION 变量

javascript - Angular:从标签中应用 ngif

php - 如果您的 mysql 查询中有某些条件(Where 子句),如何创建分页?

php - 改进我的 Zend 存储过程调用代码

php - 如何在 PHP 中打印 stdClass 对象的属性?

javascript - 为什么 react 将字符串数组渲染为 HTML 元素?

javascript - Aurelia 绑定(bind)按钮回调函数

mysql - 来自 mysql 查询的重复结果

mysql - 选择时间之间,填写空时间