Comparative Analysis of the use of PHP and Java date-time function examples
This article mainly introduces the relevant knowledge of "comparative analysis of PHP and Java date-time function examples". Xiaobian shows you the operation process through actual cases. The operation method is simple and fast and practical. I hope this article "comparative analysis of PHP and Java date-time function examples" can help you solve the problem.
date(): Format a local time or date, current time May 13, 2016 15:19:49
Use the function date() to output the current day of the month, parameter: String type d
For example: echo date("d"); output 13
Use the function date() to output the current day of the week, parameters: String type D or N
For example:
echo date("D"); outputs Friecho date("N"); outputs 5echo date("l"); outputs Friday
Use the function date() to output the month of the current month, parameters: String type n
echo date("n"); Output 5
Use the function date() to determine whether the current year is a leap year, parameters: String type L
echo date("L"); Output 1
strtotime(): converts string type date format to timestamp
Use the function strtotime() to print the date of the previous day, parameters: String type "-1 day"
echo date("Y-m-d H:i:s",strtotime("-1day")); output 2016-05-12 15:27:33
Use the function strtotime() to print tomorrow's date, parameters: String type "+1 day"
echo date("Y-m-d H:i:s",strtotime("+1 day")); output 2016-05-14 15:28:29
Use strtotime() function to print next week's date, parameters: String type "+1 week"
echo date("Y-m-d H:i:s",strtotime("+1 week"));; output 2016-05-20 15:29:35
Use strtotime() function to print the date of the next month, parameters: String type "+1 month"
echo date("Y-m-d H:i:s",strtotime("+1 month")); output: 2016-06-13 15:37:42
Use strtotime() function to print the next Monday date, parameters: String type "last Mondy"
echo date("Y-m-d H:i:s",strtotime("next Monday")); output: 2016-05-16 00:00:00
Use the function strtotime() to print the date two days, two hours and two seconds after next week. Parameters: String type combination
echo date("Y-m-d H:i:s",strtotime("+1 week 2 day 2 hour")); output 2016-05-22 17:34:34
==================================================================
Java version:
java.util.Date class
Get Date object, new comes out
Call getTime() method of Date object to get timestamp (millisecond value)
java.text.SimpleDateFormat class
Get SimpleDateFormat object, new out, construction parameters: "y-MM-dd hh:mm:ss"
Call format() method of SimpleDateFormat object to get date of String type, parameter: Date object
For example:
Date date=new Date(); SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); System.out.println(format.format(date)); This is where the content of "Comparative analysis of PHP and Java date-time function examples" is introduced. Thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.