怎么在PHP中对时间进行格式化

  介绍

怎么在PHP中对时间进行格式化?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

具体如下:

/* *   ,*格式化时间   ,* @param  time 美元时间戳   ,* @return  bool |字符串   ,*/function  formatTimeToNow(美元){//才能获取现在的时间戳=美元才能nowtime 拖延时间();   如果才能(time> nowtime美元){   ,,,return  & # 39; & # 39;;   }{其他才能   ,,,tc 美元;=,nowtime -时间美元;   如果(,,,,,tc 美元的在=,864000,){   ,,,,,str 美元;=,日期(& # 39;Y-m-d  H:我# 39;,美元);//如果大于10天,则直接显示日期   ,,,}else 如果(,tc 美元;祝辞=,86400){   ,,,,,str 美元;=,地板(tc/86400美元),只“天前“;//如果大于1天   ,,,}else 如果(,tc 美元;祝辞=,3600),{   ,,,,,str 美元;=,地板(tc 美元/,3600),只“小时前“;//如果大于1小时   ,,,}else 如果(,tc 美元;祝辞=,60),{   ,,,,,str 美元;=,地板(tc 美元/,60),只“分钟前“;//如果大于1分钟   还有,,,}{   ,,,,,str 美元;=,“刚刚“;   ,,,}   ,,,return  str美元;   ,,}   } /* *   ,*将中文的日期格式化为正常的日期   ,* @param  $日期   ,* @return 混合   ,*/function  formatCnDateToDate(日期){//才能把年月替换为,日替换为空   时间=美元才能date  str_replace(& # 39;年& # 39;& # 39;& # 39;,美元日期);   时间=美元才能date  str_replace(& # 39;月& # 39;& # 39;& # 39;,美元日期);   时间=美元才能date  str_replace(& # 39;日& # 39;& # 39;& # 39;,美元日期);//才能避免提交的格式不统一,例如2018-3-2等,标准化   return 才能;日期(& # 39;Y-m-d& # 39;, strtotime(日期)美元);   } /* *   ,*计算自然周期的开始时间戳和结束时间戳(周一到周日、月初到月末)   ,* @param  int  time_type 美元;1表示自然天,2表示自然周、3表示自然月   ,* @param  int  prev_num 美元;距离现在的值(前一周传1,前两周传2…)   ,* | bool @return 数组   ,*/function  naturalFormatTime (time_type=1, prev_num美元=0){   时间=美元才能today_start_time  strtotime(日期(& # 39;Y-m-d 就是# 39;,时间()));//今天0点的时间戳   如果才能(time_type 美元;==,1){   ,,,如果(prev_num 美元;==,0){   ,,,,,return 数组(& # 39;start_time& # 39;=祝辞today_start_time美元,& # 39;end_time& # 39;=在时间()& # 39;show_date& # 39;=祝辞日期(& # 39;Y年m月d日& # 39;,时间()));   ,,,}else 如果(prev_num 美元;& lt;, 0) {   ,,,,,start_time 美元;=,today_start_time 美元;作用;86400 * abs ($ prev_num);   ,,,,,end_time 美元;=,start_time 美元;+,86399;   ,,,,,show_date 美元;=,日期(& # 39;Y年m月d日& # 39;,start_time美元);   ,,,,,return 数组(& # 39;start_time& # 39;=祝辞start_time美元,& # 39;end_time& # 39;=祝辞end_time美元,& # 39;show_date& # 39;=祝辞show_date美元);   还有,,,}{   ,,,,,return 假;   ,,,}   }才能else 如果(==time_type 美元;2){   ,,,today_week 美元;=,日期(& # 39;w # 39;, today_start_time美元);   ,,,如果(today_week 美元;==,0){   ,,,,,today_week_start_time 美元;=,today_start_time 美元;作用;86400 * 6;   还有,,,}{   ,,,,,today_week_start_time 美元;=,today_start_time 美元;作用;86400 * ($ today_week-1);   ,,,}   ,,,如果(prev_num 美元;==,0){   ,,,,,show_date 美元;=,日期(& # 39;Y年m月d日& # 39;,today_week_start_time美元);   ,,,,,show_date 美元。=,& # 39;至& # 39;,只日期(& # 39;d日& # 39;,时间());   ,,,,,return 数组(& # 39;start_time& # 39;=祝辞today_week_start_time美元,& # 39;end_time& # 39;=在时间()& # 39;show_date& # 39;=祝辞show_date美元);   ,,,}else 如果(prev_num 美元;& lt;, 0) {   ,,,,,start_time 美元;=,today_week_start_time 美元;作用;86400 * 7,*,abs ($ prev_num);   ,,,,,end_time 美元;=,start_time 美元;+,(86400 * 7 - 1);   ,,,,,show_date 美元;=,日期(& # 39;Y年m月d日& # 39;,start_time美元);   ,,,,,show_date 美元。=,& # 39;至& # 39;,只日期(& # 39;d日& # 39;,end_time美元);   ,,,,,return 数组(& # 39;start_time& # 39;=祝辞start_time美元,& # 39;end_time& # 39;=祝辞end_time美元,& # 39;show_date& # 39;=祝辞show_date美元);   还有,,,}{   ,,,,,return 假;   ,,,}   }才能else 如果(==time_type 美元;3){   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

怎么在PHP中对时间进行格式化