简体   繁体   English

比我的时间晚 9 小时 30 分钟

[英]Add 9 hours and 30 minutes behind my time

I have a mysql database table that gets the "datetime" column automatically filled when a user fills in the php form page.我有一个 mysql 数据库表,当用户填写 php 表单页面时,它会自动填充“日期时间”列。

$timestamp = datetime("Y-m-d H:i:s");

Trouble is, the database server is in the USA which is 9 hours 30 minutes behind my time.麻烦的是,数据库服务器在美国,比我的时间晚了 9 小时 30 分钟。

Does anyone know a way to change this so that the 9 hours 30 minutes hours get added to the datetime?有谁知道改变这一点的方法,以便将 9 小时 30 分钟的时间添加到日期时间?

To answer your question directly, you can use the following function in your select statement:要直接回答您的问题,您可以在 select 语句中使用以下 function :

select date_add(datefield, interval 570 minute) from table

However, as stated in some of the comments it's best if you correct the problem from the source and update the timezone in your DBMS.但是,如某些评论中所述,最好从源头纠正问题并更新 DBMS 中的时区。

You could always just use date which has an argument for timezone.您总是可以只使用具有时区参数的日期 http://www.php.net/manual/en/function.date.php http://www.php.net/manual/en/function.date.php

There are several possibilities.有几种可能性。 See http://www.php.net/manual/en/ref.datetime.php for a list of DateTime-Functions.有关日期时间函数的列表,请参阅http://www.php.net/manual/en/ref.datetime.php date_add and date_sub are good candidates to start with date_add 和 date_sub 是很好的开始

1) Set the correct timezone in the php.ini file. 1) 在 php.ini 文件中设置正确的时区。
2) Set the correct timezone in your DBMS ( MySQL timezone change? for MySQL) 2) 在您的 DBMS 中设置正确的时区( MySQL timezone change? for MySQL)

This won't require you to add some weird parameters or constantly use the same functions in your scripts.这不需要您添加一些奇怪的参数或在脚本中不断使用相同的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM