2012-11-04 37 views
2

我可以将PHP转换为IST而不使用PEAR。PHP将GMT转换为IST

这是我如何得到GMT gmdate(),现在我该怎样将其转换为IST。

感谢

回答

9

尝试

echo date('Y-m-d H:i:s',strtotime('+330 minutes', 0)); 

date_default_timezone_set('Asia/Kolkata'); 
    echo date('Y-m-d H:i:s'); 

首先

$time = new DateTime('now', new DateTimeZone('UTC')); 
    // than convert it to IST by 
    $time->setTimezone(new DateTimeZone('IST')); 
+0

:我有一个应用程序,最终用户可能来自任何国家,但是当他使用的应用程序,我想在sotre日期IST.How我能做到这一点? – ram

+0

@ram:当然要询问用户的时区。 –

+0

@ram为什么?日期最好以UTC格式存储,并且仅在需要输出时才会与当地时区相偏移 –

2

易peasy获取时间:

$date = new DateTime('2012-11-04 05:04:00', new DateTimeZone('GMT')); 
$date->setTimezone(new DateTimeZone('IST')); 

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