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
  • Is it allowed only GMT ? – Mani Dec 4 '17 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 – Stephen Ostermiller Dec 4 '17 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.