简体   繁体   English

PHP time() 方法未提供我的时区时间戳

[英]PHP time() method not giving timestamp of my timezone

I have a php code which inserts the timestamp in the database for every insert.我有一个 php 代码,它为每次插入在数据库中插入时间戳。

I use: time() method to get the time Stamp.我使用: time()方法来获取时间戳。 but when I send this time Stamp to the mobile client it shows some other time.但是当我将这个时间戳发送到移动客户端时,它会显示其他时间。

How do I get the timestamp for my current time zone, Asia/Calcutta .如何获取当前时区Asia/Calcutta的时间戳。

Here is my PHP code:这是我的 PHP 代码:

 date_default_timezone_set('Asia/Calcutta');
 $timeStamp = time();
 //insert into notification table
 $sql = "insert into notifications (senderUsername,notificationText,timeStamp) values ('$senderUsername','$resultTextValue','$timeStamp')";

This store the value in the DB as 1420829504这将数据库中的值存储为1420829504

This when parsed on my Android client it shows as January 9th 2015, 18:51:44 but I except it as January 10th 2015, 00:21:44这在我的 Android 客户端上解析时显示为January 9th 2015, 18:51:44但我将其排除为January 10th 2015, 00:21:44

I have already deployed my application on the Play Store, so the only thing I can play with is my server side code.我已经在 Play Store 上部署了我的应用程序,所以我唯一可以玩的就是我的服务器端代码。

You can set your time zone on a per project basis for php like so.您可以像这样在每个项目的基础上为 php 设置时区。

date_default_timezone_set('Asia/Calcutta');

    date_default_timezone_set('Asia/Kolkata');
    $time = time();
    $actual_time = date('M d Y, 00:H:i',$time);

use $actual_time in you sql database在你的 sql 数据库中使用 $actual_time

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

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