开发者

PHP / MySQL - current date/time in timezone

开发者 https://www.devze.com 2023-03-12 09:50 出处:网络
How do request the date/time in PHP or MySQL within a timezone? I\'d rather do it on the PHP side, but also would like to know if its possible开发者_Go百科 in MySQL.SET GLOBAL time_zone = timezone;

How do request the date/time in PHP or MySQL within a timezone? I'd rather do it on the PHP side, but also would like to know if its possible开发者_Go百科 in MySQL.


SET GLOBAL time_zone = timezone;

Or per connection:

SET time_zone = timezone;


First of all, you can return Unix time, which is universal time, like that:

  • in MySQL (UNIX_TIMESTAMP() documentation):

    SELECT UNIX_TIMESTAMP();
    
  • in PHP (time() documentation):

    echo time();
    

If you want the time in your current time zone, you can do it like that:

  • in MySQL (NOW() documentation):

    SELECT NOW();
    
  • in PHP (for available formats refer to date() documentation):

    echo date('Y-m-d H:i:s');
    

Does it meet your needs?

0

精彩评论

暂无评论...
验证码 换一张
取 消