Remove leading zeros from abbreviated date with PHP

后端 未结 2 1597
太阳男子
太阳男子 2021-01-06 00:06

I was wondering if there is a way, using PHP, to change this date format: 01.08.86 (January 8, 1986) to this format: 1.8.86.

相关标签:
2条回答
  • 2021-01-06 00:55

    How about a regex based solution:

    $str = '01.08.86';
    $a = array('/^0(\d+)/','/\.0(\d+)/');
    $b = array('\1','.\1');
    $str = preg_replace($a,$b,$str);
    
    // $str is now '1.8.86'
    
    0 讨论(0)
  • 2021-01-06 01:04
    <?php
    
    $date = "01.08.86";
    $unix = strtotime($date);
    echo date('n.j.y', $unix);
    
    0 讨论(0)
提交回复
热议问题