PHP Learning _php Tutorials on time

Source: Internet
Author: User
About the function of time:

Strftime formatting local time/date based on regional settings

strptime-parsing date/time generated by strftime ()

setlocale function Setting Region information (Geographic information)

Date_default_timezone_set if the date function is found to be 8 hours apart from the actual number of hours, please add date_default_timezone_set (' etc/gmt-8 ');

date-formatting a local time/date

Gmdate is exactly the same as date-formatting a GMT/UTC date/time

mktime-get a date for Unix timestamp mktime (0, 0, 0, 12, 30, 1997)

Gmmktime and Mktime are exactly the same.

strtotime-to parse the datetime description of any English text into a UNIX timestamp

time-returns the current UNIX timestamp

microtime-returns the current UNIX timestamp and number of microseconds

Getlastmod-get the last time the page content was updated in the current use

Note: Timestamp is not a function that refers to the number of seconds that a Unix timestamp is from January 01, 1970 0:0 0 seconds to a moment

Actual Operation case

$strtime = "2000-02-12 16:20:35";

$array = Explode ("-", $strtime);

$year = $array [0];

$month = $array [1];

Var_dump ($array);

$array = Explode (":", $array [2]);

$minute = $array [1];

$second = $array [2];

Var_dump ($array);

$array = Explode ("", $array [0]);

$day = $array [0];

$hour = $array [1];

$timestamp = Mktime ($hour, $minute, $second, $month, $day, $year);

echo "String time: $strtime
";

echo "Year: $year
";

echo "Month: $month
";

echo "Day: $day
";

echo "When: $hour
";

echo "Score: $minute
";

echo "Seconds: $second
";

echo "converted to timestamp:". $timestamp. "
";

echo "converted from timestamp back:". Date ("Y-m-d h:i:s", $timestamp). "
";

echo "converted from timestamp back:". Date ("Y-m-d h:i:s", "1288263141"). "
";

Header ("content-type:text/html; Charset=utf-8 ");

Echo (Strtotime ("2010-10-28 10:52:21")). "
"; MySQL format string converted to seconds

Echo (Strtotime ("2010-10-01 00:00:00")). "
";

$d = Date ("Y-m-d h:i:s", Time ()); Seconds converted to timestamp in MySQL format

echo $d. "
";

The result is:

Array

0 = String ' a ' (length=4)

1 = String ' in ' (length=2)

2 = String ' 16:20:35 ' (length=11)

Array

0 = String ' (length=5)

1 = String ' (length=2)

2 = String ' (length=2)

String time: 2000-02-12 16:20:35

Year: 2000

Month: 02

Day: 12

Hours: 16

Points: 20

Seconds: 35

Convert to timestamp:950372435

Convert from timestamp back: 00-02-12 04:20:35

Convert from timestamp back: 10-10-28 10:52:21

1288263141

1285891200

2011-10-20 14:48:27

Common values for formatting time functions

The function date (string format [, int timestamp]) can format the date/time, the parameter format is the formatted string, and the most common values are as follows:

Year of the full representation of y:4 digits

Y:2 number of years represented by a digit

M: The month represented by numbers

M: three-letter abbreviation for month

D: The day ordinal of the month

D: The day of the week

H: Hour, 12-hour format, with leading zeros

H: Hour, 24-hour format, with leading zeros

I: Number of minutes with leading zeros

I: is daylight saving time

S: Number of seconds

S: English suffix after the number of days of the month, 2 characters

W: The day of the week, the number indicates

Week of the w:iso-8601 format year, starting from Monday

L: Day of the week, full text format

L: Whether it is a leap year

G:12 hour format with no leading zeros

G: 24-hour format with no leading zeros

If you find that the number of hours from the date function differs from the actual 8 hours, add date_default_timezone_set (' etc/gmt-8 ');

The GETDATE (timestamp) function can obtain date/time information.

Returns a associative array that contains date information, based on timestamp. If the timestamp is not given, it is considered the current local time.

The cells in the array are as follows:

Key Name

Description

Example of return value

"Seconds"

The number of seconds is expressed

0 to 59

"Minutes"

The number of minutes indicates

0 to 59

"Hours"

The number of hours indicates

0 to 23

"Mday"

The number of days in the month indicates

1 to 31

"Wday"

The number of days of the week indicates

0 (for Sunday) to 6 (= Saturday)

"Mon"

Numeric representation of the month

1 to 12

"Year"

Full Year 4-digit representation

Example: 1999 or 2003

"Yday"

The number of days in a year indicates

0 to 365

"Weekday"

Full text representation of the day of the week

Sunday to Saturday

"Month"

Full text representation of the month

January to December

0

The number of seconds since the Unix era began, similar to the return value of time () and the value used for date ().

System-dependent, typical values are from 2147483648 to 2147483647.

Instance:

Format displayed: Year-month-day hour: minute: Wonderful

$showtime =date ("y-m-d h:i:s");

Echo ' shows the time in the format: '. $showtime. '
";

The result is:

The format of the display time is: 2011-10-20 14:48:27

This article is from the "PHP Technology" blog

http://www.bkjia.com/PHPjc/478577.html www.bkjia.com true http://www.bkjia.com/PHPjc/478577.html techarticle About time functions: strftime format local time/date based on locale strptime resolve the date/time setlocale function generated by the strftime () to set the region information (region letter ...

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