how to re-format datetime string in php?

后端 未结 8 980
栀梦
栀梦 2020-11-29 07:00

I receive a datetime from a plugin. I put it into a variable:

$datetime = \"20130409163705\"; 

That actually translates to yyyymm

8条回答
  •  清歌不尽
    2020-11-29 07:49

    If you want to use substr(), you can easily add the dashes or slashes like this..

    $datetime = "20130409163705"; 
    $yyyy = substr($datetime,0,4);
    $mm = substr($datetime,4,6);
    $dd = substr($datetime,6,8);
    $hh = substr($datetime,8,10);
    $MM = substr($datetime,10,12);
    $ss = substr($datetime,12,14);
    $dt_formatted = $mm."/".$dd."/".$yyyy." ".$hh.":".$MM.":".$ss;
    

    You can figure out any further formatting from that point.

提交回复
热议问题