[PHP] 重回基础(date函数和strtotime函数),datestrtotime_PHP教程

WBOY
Release: 2016-07-12 08:52:39
Original
776 people have browsed it

[PHP] 重回基础(date函数和strtotime函数),datestrtotime

 

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));

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1125993.htmlTechArticle[PHP] 重回基础(date函数和strtotime函数),datestrtotime date():格式化一个本地时间或者日期,当前时间 2016年5月13日 15:19:49 使用函数date(),输...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!