博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在js中将日期转换为字符串_在PHP中将日期显示为今天,昨天等
阅读量:2533 次
发布时间:2019-05-11

本文共 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/

你可能感兴趣的文章
ThreadLocal为什么要用WeakReference
查看>>
删除本地文件
查看>>
FOC实现概述
查看>>
base64编码的图片字节流存入html页面中的显示
查看>>
这个大学时代的博客不在维护了,请移步到我的新博客
查看>>
GUI学习之二十一——QSlider、QScroll、QDial学习总结
查看>>
nginx反向代理docker registry报”blob upload unknown"解决办法
查看>>
gethostbyname与sockaddr_in的完美组合
查看>>
kibana的query string syntax 笔记
查看>>
旋转变换(一)旋转矩阵
查看>>
thinkphp3.2.3 bug集锦
查看>>
[BZOJ 4010] 菜肴制作
查看>>
C# 创建 读取 更新 XML文件
查看>>
KD树
查看>>
VsVim - Shortcut Key (快捷键)
查看>>
C++练习 | 模板与泛式编程练习(1)
查看>>
HDU5447 Good Numbers
查看>>
08.CXF发布WebService(Java项目)
查看>>
java-集合框架
查看>>
RTMP
查看>>