如何在表单邮件中使用php将时间更改为国家/地区


how to change time to country with php in form mail

我使用此代码显示时间

$in_Body .= 'Time: ' .  gmdate('F j, Y, h:i:s A') . "'n'n";

但我想按国家显示时间,如埃及

完整代码

<?php
$webmaster_mail = 'sales@elfnoon.com';
$redirect_page = 'elfnoon.com/';
$message_subject = 'رسالة من زائر لموقعك';
$in_Body ='';
foreach($_POST as $in_k=>$in_v) {
  $in_Body .="$in_k = $in_v'n'n";
}
$in_Body .= 'IP: ' . $_SERVER['REMOTE_ADDR'] . "'n'n";
$in_Body .= 'Browser: ' . $_SERVER['HTTP_USER_AGENT'] . "'n'n";
$in_Body .= 'Time: ' .  gmdate('F j, Y, h:i:s A') . "'n'n";
mail(trim($webmaster_mail), "$message_subject ", "$in_Body","From: " . trim($webmaster_mail));
header("Location: $redirect_page");
?>

知道吗???

如果您想使用埃及时间,请查看date_default_timezone_set和支持的时区列表。

gmdate返回基于GMT时区的时间。埃及是UTC+2。

在代码中设置时区:-

 ini_set('date.timezon','Europe/Brussels');  

或者试试这个

<?php
ini_set('date.timezon','Europe/Brussels');
$webmaster_mail = 'sales@elfnoon.com';
$redirect_page = 'elfnoon.com/';
$message_subject = '????? ?? ???? ??????';
$in_Body ='';
foreach($_POST as $in_k=>$in_v) {
  $in_Body .="$in_k = $in_v'n'n";
}
$in_Body .= 'IP: ' . $_SERVER['REMOTE_ADDR'] . "'n'n";
$in_Body .= 'Browser: ' . $_SERVER['HTTP_USER_AGENT'] . "'n'n";
$in_Body .= 'Time: ' .  gmdate('F j, Y, h:i:s A') . "'n'n";
mail(trim($webmaster_mail), "$message_subject ", "$in_Body","From: " . trim($webmaster_mail));
header("Location: $redirect_page");
?>