PHP vs Java Learning date Time function _php tips

Source: Internet
Author: User

Let's talk about the first look at PHP

date (): format a local time or date, current time May 13, 2016 15:19:49

Using the function date (), the output is currently the day of the month, parameter: string Type D

For example: Echo date ("D"); Output 13

Using the function date (), the output is currently the day of the week, parameter: String type D or N

For example:

echo Date ("D"); Output Fri

echo Date ("N"); output 5

echo date ("L"); output Friday

Use the function date () to output the month ordinal of the current month, parameter: String type N

echo date("n"); 输出 5

Use the function date () to determine whether the current year is a leap years, parameters: String Type L

echo date("L"); 输出 1

Strtotime (): Convert string type date format to timestamp

Use function Strtotime (), Print day before date, parameters: String Type "-1 days"

echo date("Y-m-d H:i:s",strtotime("-1day"));Output 2016-05-12 15:27:33

Use function Strtotime (), print tomorrow date, Parameters: String Type "+1 Day"

echo date("Y-m-d H:i:s",strtotime("+1 day"));Output 2016-05-14 15:28:29

Using function Strtotime (), print the next Sunday period, Parameters: String Type "+1 Week"

echo date("Y-m-d H:i:s",strtotime("+1 week"));;Output 2016-05-20 15:29:35

Use function Strtotime () to print the next one month date, parameter: String type "+1 Month"

echo date("Y-m-d H:i:s",strtotime("+1 month")); Output: 2016-06-13 15:37:42

Using function Strtotime (), Print next week, 1st, Parameters: String Type "last Mondy"

echo date("Y-m-d H:i:s",strtotime("next Monday")); Output: 2016-05-16 00:00:00

Use function Strtotime (), Print next week 2 days two hours two seconds after date, parameter: String type Combine

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 out

Call the GetTime () method of the Date object to get the timestamp (millisecond value)

Java.text.SimpleDateFormat class

Get SimpleDateFormat object, new out, construct parameter: "Yyyy-mm-dd hh:mm:ss"

invokes the format () method of the SimpleDateFormat object, obtaining a date of type string, parameter: the Dates 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.