如何在PHP中将GMT + 5.5转换为正常时间

时间:2014-11-14 05:02:03

标签: php

我写了以下代码,它给了我UTC时间(默认时区为" UTC") 如何将UTC时间转换为GMT + 5.5

$todaysDate= date("Y-m-d-h-i-a");                                        
list($year,$month,$day,$hour,$minute,$meridian) = explode('-',$todaysDate);
$dtime = mktime($hour,$minute, 0, $month, $day, $year);
$dtime = $dtime + ($_SESSION['user_time_zone_offset'] * 60 * 60);
$dtime = date("H:i a", $dtime);                  
echo $dtime;

2 个答案:

答案 0 :(得分:0)

使用它:

date_default_timezone_set("Asia/Calcutta");

应该有效

答案 1 :(得分:0)

对于GMT + 5.5,最好在php文件中使用如下代码.........

<?php session_start();
    date_default_timezone_set("Asia/Calcutta");
    $todaysDate= date("Y-m-d-h-i-a");                                        
    list($year,$month,$day,$hour,$minute,$meridian) = explode('-',$todaysDate);
    $dtime = mktime($hour,$minute, 0, $month, $day, $year);
    //$dtime = $dtime + ($_SESSION['user_time_zone_offset'] * 60 * 60);
    $dtime = date("H:i a", $dtime);                  
    echo $dtime;
?>

&LT;&LT; Out put给印度当前时间&gt;&gt; 请在发布新问题之前搜索类似的问题....