[PHP] Back to basics (date function and Strtotime function), datestrtotime_php tutorial

Source: Internet
Author: User
Tags echo date

[PHP] Back to basics (date function and Strtotime function), datestrtotime


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 ordinal of the month, parameter: string Type D

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

Using the function date (), the output is currently the day ordinal 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"); Output 5

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

echo Date ("L"); Output 1

Strtotime (): Turns the string type date format into a timestamp

Use function Strtotime () to print the date of the previous day, parameter: String type "1 day"

echo Date ("Y-m-d h:i:s", Strtotime (" -1day")); output 2016-05-12 15:27:33

Use function Strtotime () to print tomorrow's date, parameter: String type "+1 Day"

echo Date ("Y-m-d h:i:s", Strtotime ("+1 Day"); output 2016-05-14 15:28:29

Use the function strtotime () to 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 the 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, parameter: 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 later date, parameter: 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 Edition:

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"

Call the format () method of the SimpleDateFormat object to get a string of type date, 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));

http://www.bkjia.com/PHPjc/1125993.html www.bkjia.com true http://www.bkjia.com/PHPjc/1125993.html techarticle [PHP] Back to basics (date function and Strtotime function), Datestrtotime date (): Format a local time or date, current time May 13, 2016 15:19:49 use function date (), Lose ...

  • 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.