users to view in local timezone

后端 未结 2 951
温柔的废话
温柔的废话 2021-01-20 20:01

I\'ve asked a very similar question before but got no answers that helped.

I have a site that allows users to post notes. There will be a time stamp on those notes.

2条回答
  •  孤街浪徒
    2021-01-20 20:34

    You could use PHPs DateTime and DateTimeZone to convert the datetime into the users current timezone:

    http://www.php.net/manual/de/class.datetime.php
    http://www.php.net/manual/de/class.datetimezone.php

    $date = new DateTime($dateTimeFromDB);
    $date->setTimeZone( new DateTimeZone('User/Timezone') );
    
    echo $date->format('d.m.Y H:i');
    

提交回复
热议问题