PHP timestamp date to user timezone

前端 未结 1 1692
耶瑟儿~
耶瑟儿~ 2020-12-15 12:31

I\'m pulling the raw generated mysql timestamp info of $item_date from the database as php date format:

if (($timestamp = strtotime($item_date)) === false) {         


        
1条回答
  •  悲&欢浪女
    2020-12-15 12:53

    This post has been updated to include a full-fledged example

    setTimestamp($item_date);
    
            //just for the fun: what would it be in UTC?
            $dt->setTimezone(new DateTimeZone("UTC"));
            $would_be = $dt->format('Y-m-d H:i:sP');
    
            $dt->setTimezone(new DateTimeZone($_SESSION['tz']));
            $is = $dt->format('Y-m-d H:i:sP');
    
            echo "Timestamp " . $item_date . " is date " . $is . 
                 " in users timezone " . $dt->getTimezone()->getName() .
                 " and would be " . $would_be . " in UTC
    "; } ?>

    I hope this is now clear enough ;).

    0 讨论(0)
提交回复
热议问题