php EDT/EST时间转换
我的代码如下:php EDT/EST时间转换,php,Php,我的代码如下: <?php function my_time($zone,$dst){ if ($dst=='on') { // bellow codes will return time date when DST is on/EDT time $dateTime = new DateTime('now', new DateTimeZone($zone)); $dst_on = $dateTime->format("d-m-Y h:i A");
<?php
function my_time($zone,$dst){
if ($dst=='on') {
// bellow codes will return time date when DST is on/EDT time
$dateTime = new DateTime('now', new DateTimeZone($zone));
$dst_on = $dateTime->format("d-m-Y h:i A");
return $dst_on;
}elseif ($dst=='off') {
// bellow codes will return time date when DST is off/EST time
$dateTime = new DateTime('now', new DateTimeZone($zone));
$dst_off = $dateTime->format("d-m-Y h:i A");
return $dst_off.' (Wrong output, i need DST off/EST output here! Please help)'; // Please help me to return dst off / EST time here
}
}
echo my_time('America/New_York','off');
?>
将
关闭
参数传递到我的时间
函数时,我需要正确的输出。如何实现这一点?根据文档,没有办法关闭DST,也不应该这样做
但是,我认为这样做可能会奏效:
function my_time($zone, $dst = true) {
$dateTime = new \DateTime('now', new \DateTimeZone($zone));
if ($dst) {
$dateTime->setTimezone(new \DateTimeZone('US/Pacific'));
}
return $dateTime->format('d-m-Y, h:i A');
}
echo my_time('America/New_York', false);
我对你的代码做了一点改动,但从我使用“US/Pacific”时看到的情况来看,时间应该是EDT。我还把DST改成了bool,这样读起来就更好了