[PHP] 重回基础(date函数和strtotime函数)
date():格式化一个本地时间或者日期,当前时间 2016年5月13日 15:19:49
使用函数date(),输出当前是月份中的第几天,参数:String类型 d
例如:echo date("d"); 输出 13
使用函数date(),输出当前是星期中的第几天,参数:String类型 D或者 N
例如:echo date("D"); 输出 Fri
echo date("N"); 输出 5
echo date("l"); 输出 Friday
使用函数date(),输出当前月份中的第几月,参数:String类型 n
echo date("n"); 输出 5
使用函数date(),判断当前年份是否是闰年,参数:String类型 L
echo date("L"); 输出 1
strtotime():把字符串类型日期格式转成时间戳
使用函数strtotime(),打印前一天日期,参数:String类型 “-1 day”
echo date("Y-m-d H:i:s",strtotime("-1day"));输出 2016-05-12 15:27:33
使用函数strtotime(),打印明天日期,参数:String类型 “+1 day”
echo date("Y-m-d H:i:s",strtotime("+1 day"));输出 2016-05-14 15:28:29
使用函数strtotime(),打印下周日期,参数:String类型 “+1 week”
echo date("Y-m-d H:i:s",strtotime("+1 week"));;输出 2016-05-20 15:29:35
使用函数strtotime(),打印下一个月日期,参数:String类型 “+1 month”
echo date("Y-m-d H:i:s",strtotime("+1 month")); 输出:2016-06-13 15:37:42
使用函数strtotime(),打印下周一日期,参数:String类型 “last Mondy”
echo date("Y-m-d H:i:s",strtotime("next Monday")); 输出:2016-05-16 00:00:00
使用函数strtotime(),打印下周零两天两小时两秒后日期,参数:String类型组合一下
echo date("Y-m-d H:i:s",strtotime("+1 week 2 day 2 hour")); 输出 2016-05-22 17:34:34
==================================================================
java版:
java.util.Date类
获取Date对象,new出来
调用Date对象的getTime()方法,获取时间戳(毫秒值)
java.text.SimpleDateFormat类
获取SimpleDateFormat对象,new出来,构造参数:"yyyy-MM-dd hh:mm:ss"
调用SimpleDateFormat对象的format()方法,获取String类型的日期,参数:Date对象
例如:
Date date=new Date();
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
System.out.println(format.format(date));
相关文章
- 3xx HTTP状态码的终极指南
- React报错之React.Children.only expected to receive single React element child
- React报错之Element type is invalid
- React报错之Too many re-renders
- React报错之Function components cannot have string refs
- 如何发布一个 TypeScript 编写的 npm 包
- 如何使用zx编写shell脚本
- 13个构建RESTful API的最佳实践
- 什么是REST API
- React报错之Rendered more hooks than during the previous render
- 如何使用CSS伪类选择器
- React报错之Property 'value' does not exist on type EventTarget
- React报错之Parameter 'event' implicitly has an 'any' type
- React报错之Parameter 'props' implicitly has an 'any' type
- React报错之Property 'value' does not exist on type 'HTMLElement'
- React报错之You provided a `checked` prop to a form field
- React报错之Invalid hook call
- React报错之React hook 'useState' cannot be called in a class component
- React报错之React Hook 'useEffect' is called in function
- React报错之React hook 'useState' is called conditionally