Remove leading zeros from abbreviated date with PHP

爷,独闯天下 提交于 2019-12-30 06:49:28

问题


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.


回答1:


<?php

$date = "01.08.86";
$unix = strtotime($date);
echo date('n.j.y', $unix);



回答2:


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'


来源:https://stackoverflow.com/questions/2480112/remove-leading-zeros-from-abbreviated-date-with-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!