Comparison between PHP and Java learning Date and Time Functions, phpjava date functions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.