本文共 801 字,大约阅读时间需要 2 分钟。
在js中将日期转换为字符串
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.
构建一个名为$ myWeek的数组,该数组将保存今天,昨天,昨天的数组元素,然后以返回1周的一天的名称构建一周的其余时间。
function getDayName($myDate,$myWeek){ global $myWeek; // globalise the $myWeek array if($myDate> strtotime('-7 day')){ return $myWeek[(time()-$myDate)/(60*60*24)]; } else{ return date('d/m/Y',$myDate); // else just return the date as a normal date string }}
Then you just need to pass your date to the function.
然后,您只需要将日期传递给函数即可。
If it is already in timestamp format then:
如果已经采用时间戳格式,则:
$dayName = getDayName($yourdatetime);
Otherwise convert it to a timestamp:
否则将其转换为时间戳:
$dayName = getDayName(strtotime($yourdatetime));
翻译自:
在js中将日期转换为字符串
转载地址:http://wwhzd.baihongyu.com/