how to convert timestamp to date in codeigniter

后端 未结 5 1087
暗喜
暗喜 2021-01-21 19:03

I want to convert 1373892900000 to Monday 2013/07/15 8:55 AM in Codeigniter.

However, I keep receiving a totally different result by converting

5条回答
  •  孤街浪徒
    2021-01-21 19:48

    Why not just use PHP's date function?

    public function time_convert($timestamp){
       return date('l Y/m/d H:i', $timestamp);
    }
    

    For different timezones use a DateTime object:

    public function time_convert($timestamp, $timezone = 'UTC'){
        $datetime = new DateTime($timestamp, new DateTimeZone($timezone));
        return $datetime->format('l Y/m/d H:i');
    }
    

    Think that should work. Note: I tihnk you need at least PHP version 5.20 for the TimeZone class.

提交回复
热议问题