Comparison between PHP and Java learning Date and Time Functions, phpjava date functions
Let's talk about PHP first.
Date ():Format a local time or date. The current time is 15:19:49, January 1, May 13, 2016.
Use the date () function to output the day of the current month. Parameter: String type d
Example: echo date ("d"); Output 13
Use the date () function to output the day of the week. Parameter: String type D or N
For example:
Echo date ("D"); Output Friecho date ("N"); output 5 echo date ("l"); Output Friday
Use the date () function to output the nth month of the current month. Parameter: String type n
Echo date ("n"); output 5
Use the date () function to determine whether the current year is a leap year. Parameter: String type L
Echo date ("L"); Output 1
Strtotime (): converts a string-type date format to a timestamp.
Use the strtotime () function to print the date of the previous day. Parameter: String type "-1 day"
echo date("Y-m-d H:i:s",strtotime("-1day"));
Output 15:27:33
Use the strtotime () function to print tomorrow's date. Parameter: String type "+ 1 day"
echo date("Y-m-d H:i:s",strtotime("+1 day"));
Output 15:28:29
Use the strtotime () function to print the date of the next week. Parameter: String type "+ 1 week"
echo date("Y-m-d H:i:s",strtotime("+1 week"));;
Output 15:29:35
Use the strtotime () function to print the date of the next month. Parameter: String type "+ 1 month"
echo date("Y-m-d H:i:s",strtotime("+1 month"));
Output: 15:37:42
Use the strtotime () function to print the next Monday date. The parameter is String type "last Mondy"
echo date("Y-m-d H:i:s",strtotime("next Monday"));
Output: 00:00:00
Use the strtotime () function to print the date of the next week, two days, two hours, two seconds later. The parameter is a String type combination.
echo date("Y-m-d H:i:s",strtotime("+1 week 2 day 2 hour"));
Output 17:34:34
========================================================== ======================================
Java version:
Java. util. Date class
Get Date object, new
Call the getTime () method of the Date object to obtain the timestamp (millisecond value)
Java. text. SimpleDateFormat class
Obtain the SimpleDateFormat object, which is new. The construction parameter is "yyyy-MM-dd hh: mm: ss"
Call the format () method of the SimpleDateFormat object to obtain the Date of the 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));