1

I want to send the last-modified in IST timezone, But it always sends in GMT. What is wrong with this PHP code?

echo "Timezone " . date_default_timezone_get () ;  //==>verified, timezone set correctly Asia/Kolkata
$timezone = new DateTimeZone("Asia/Kolkata");
$date =  new DateTime($this->item->modified);
$date->setTimezone($timezone );
$mod_time = trim ($date->format('D, d M Y H:i:s'));
echo $mod_time;
header("Last-Modified: ". $mod_time . " IST", true)  ;
//    header("Last-Modified: ". $mod_time . " IST", true)  ;  //==> Tried this also, still sends in GMT
2
  • Is it allowed only GMT ?
    – Mani
    Commented Dec 4, 2017 at 11:48
  • The DateTime constructor takes a second argument of a timezone when creating the date. Have you tried $date = new DateTime($this->item->modified, new DateTimeZone('Asia/Kolkata'));? I'm following the example from the documentation: php.net/manual/en/datetime.settimezone.php Commented Dec 4, 2017 at 11:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.