开发者

how do i convert the date to IST using date and strtotime function in php

开发者 https://www.devze.com 2023-02-09 21:13 出处:网络
i am using a timestamp to store the current date in the database. here is what i am using. $date = date(\"dFY\");

i am using a timestamp to store the current date in the database. here is what i am using.

 $date = date("dFY");
 $timestamp = strtotime($date);

now the above code fetches the current date from the server which is hosted in U.S, whereas i would like it to store the date according to Indian time which is GMT : +05:30 , how do i make sure it insert the current date according to indian time (IST).

here is the link to the date() in PHP.

http://in3.php.net/manual/en/function.date.php

although it says i have to use the parameter O with +0530, i am unsure on how d开发者_如何学Goo i use it. please help me out on this.

thank you


The O parameter for date is for displaying the timezone difference, not for setting it.

You can set your timezone using: date_default_timezone_set('Asia/Calcutta');

Also, you should be aware that you're only creating a datestamp, not a timestamp. It will stay the same for the entire day. If you want an actual timestamp, this should suffice:

date_default_timezone_set('Asia/Calcutta');
$timestamp = time();


how about this

<?php
date_default_timezone_set('GMT');
$temp= strtotime("+5 hours 30 minutes"); 
$date = date("Y-m-d H:i:s",$temp);
echo $date
?>
0

精彩评论

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