将Y-m-d转换为Y年m月d日
Posted zmdcomeon
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将Y-m-d转换为Y年m月d日相关的知识,希望对你有一定的参考价值。
自己编写的,不能直接套用,理解后可自行变化:
$var=explode(‘ ‘,$res[‘act_starting‘]);
$var1=$var[0];
$time=explode(‘-‘,$var1);
if($time[1]<10)
{
$time[1] = str_replace("0", "", $time[1]);
}else
{
$time[1]=$time[1];
}
if($time[2]<10)
{
$time[2] = str_replace("0", "", $time[2]);
}else
{
$time[2]=$time[2];
}
$json[‘date‘]=$time[0]."年".$time[1]."月".$time[2]."日";
$time = date("Y-m-d", $time); $var=explode(‘ ‘,$time); $var1=$var[0]; $time=explode(‘-‘,$var1); if($time[1]<10){ $time[1] = str_replace("0", "", $time[1]); }else{ $time[1]=$time[1]; } if($time[2]<10){ $time[2] = str_replace("0", "", $time[2]); }else{ $time[2]=$time[2]; } $new_time = $time[0]."年".$time[1]."月".$time[2]."日";
封装后
/** * 拼装年月日 */ public function rn_date($time){ $var=explode(‘ ‘,$time); $var1=$var[0]; $time=explode(‘-‘,$var1); if($time[1]<10){ $time[1] = str_replace("0", "", $time[1]); }else{ $time[1]=$time[1]; } if($time[2]<10){ $time[2] = str_replace("0", "", $time[2]); }else{ $time[2]=$time[2]; } $new_time = $time[1]."月".$time[2]."日"; return $new_time; }
以上是关于将Y-m-d转换为Y年m月d日的主要内容,如果未能解决你的问题,请参考以下文章
Laravel:在保存到数据库之前从 jQuery UI Datepicker 将 m/d/Y 转换为 Y-m-d
php 将获取到的date(time())转换成date("Y年m月d日h时i分s秒")
JS或者jQuery中怎么处理时间戳为Y-m-d 这样的格式