PHP获取各种日期时间方式方法整理

2019-03-1021:09:47后端程序开发PHP获取各种日期时间方式方法整理已关闭评论2,245 views字数 830阅读模式

PHP获取各种日期时间方式方法整理文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

日期和时间是我们在开发过程中经常用到的,在php中可以通过各种方法获取到我们需要的日期和时间,下面是整理的一些常用方法文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

date() //函数d 相关参数文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

<?php echo $showtime=date("Y-m-d H:i:s");?>文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// 显示的格式: 年-月-日 时:分:秒文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// 相关时间参数: 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// a - "am" 或是 "pm" 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// A - "AM" 或是 "PM" 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// d - 几日,二位数字,若不足二位则前面补零; 如: "01" 至 "31" 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// D - 星期几,三个英文字母; 如: "Fri" 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// F - 月份,英文全名; 如: "January" 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// h - 12 小时制的小时; 如: "01" 至 "12" 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// H - 24 小时制的小时; 如: "00" 至 "23" 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// g - 12 小时制的小时,不足二位不补零; 如: "1" 至 12" 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// G - 24 小时制的小时,不足二位不补零; 如: "0" 至 "23" 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// i - 分钟; 如: "00" 至 "59" 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// j - 几日,二位数字,若不足二位不补零; 如: "1" 至 "31" 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// l - 星期几,英文全名; 如: "Friday" 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// m - 月份,二位数字,若不足二位则在前面补零; 如: "01" 至 "12" 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// n - 月份,二位数字,若不足二位则不补零; 如: "1" 至 "12" 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// M - 月份,三个英文字母; 如: "Jan" 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// s - 秒; 如: "00" 至 "59" 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// S - 字尾加英文序数,二个英文字母; 如: "th","nd" 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// t - 指定月份的天数; 如: "28" 至 "31" 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// U - 总秒数 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// w - 数字型的星期几,如: "0" (星期日) 至 "6" (星期六) 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// Y - 年,四位数字; 如: "1999" 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// y - 年,二位数字; 如: "99" 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

// z - 一年中的第几天; 如: "0" 至 "365"文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

<?php文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

//本周一文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

echo date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600));文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

//w为星期几的数字形式,这里0为周日文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

 文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

//本周日文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

echo date('Y-m-d', (time() + (7 - (date('w') == 0 ?文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/9908.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/bc/9908.html