Date and time processing technology _php Tutorial

Source: Internet
Author: User
Tags php language locale
Processing techniques for date and time

The concept of time in PHP
Unix time stamp
Processing of dates and times

1. PHP Time Concept

In the PHP language, date and time functions depend on the locale of the server, and PHP defaults to the standard GMT, which is the 0 time zone. So to get the local current time, you must change the time zone setting in the PHP language, either by setting it in the php.ini file or by using the Date_default_timezone_set function.

Set the time zone in the php.ini file, date.timezone=xxx
The Date_default_timezone_set () function sets the time zone, using this function before the date, time function. If the server is using a 0 time zone, you cannot modify the php.ini file directly, and you can only set the time zone through the Date_default_timezone_set () function.


2. Time stamp

1. Get time stamp of any date and time
The Mktime () function converts a time to a Unix timestamp. The Mktime () function returns the UNIX timestamp according to the given parameters, whose parameters can be omitted from right to left, any omitted parameters are set to the cost date, the current value of the time (that is, no parameters are set, the Mktime () function obtains the local current date and time). Mktime (hours, minutes, seconds, months, days, years, whether daylight saving time)
Mktime () Gets the timestamp of the current time without setting any parameters.

2. Gets the current timestamp, and PHP also provides a function to get the timestamp of the current time, the time () function.

3. Date, time conversion to UNIX timestamp
The strtotime () function resolves the date description of any English text to a Unix timestamp.


3. Date and time processing

Date and time processing can be divided into formatted date and time, get information about the date and time, get the validity of the date and time of the test for localized dates and times, etc.
The date () function formats local dates and times,
The GETDATE () function returns the date, time information, in the form of an array, whichever is the current time, if there is no timestamp.
Validity of the inspection date and time, Checkdate ()


The author "technology is king"

http://www.bkjia.com/PHPjc/478616.html www.bkjia.com true http://www.bkjia.com/PHPjc/478616.html techarticle Date and time processing technology PHP Time concept UNIX timestamp date and time processing 1, PHP time concept in the PHP language, date, time function depends on the locale of the server, ...

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