Resolve a date or time description of any English text to a Unix timestamp

Source: Internet
Author: User
Tags current time php tutorial

Definitions and usage
The strtotime () function resolves the date-time description of any English text to a Unix timestamp.

Grammar
Strtotime (time,now) parameter description
Time to specify the string to parse.
Now is the time stamp used to calculate the return value. If this argument is omitted, the current time is used.

Description
The function expects to accept a string containing the U.S. English date format and tries to resolve it to a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT), with a value relative to the time given by the now parameter, or the current time of the system if this parameter is not supplied.

The function will use the TZ environment variable (if any) to compute the timestamp. There are easier ways to define a time zone for all date/time functions from PHP 5.1.0.
This procedure is described in the Date_default_timezone_get () function page.


PHP Date_default_timezone_get () function
PHP date/time function
Definitions and usage
The Date_default_timezone_get () function returns the default time zone used by all date-time functions in the script.

Grammar
Date_default_timezone_get (void) parameter description
void Optional.

Description
This function returns the default time zone, using the following "assumed" order:

Time zone set with the Date_default_timezone_set () function (if set)
TZ environment variable (if not null)
Date.timezone configuration options (if set)
Speculate on your own (if the operating system supports)
Return UTC If none of the above selections are successful
Example
<?php Tutorial
Echo (Date_default_timezone_get ());
?> output:

Europe/paris


return value
Success returns a timestamp, otherwise it returns FALSE. This function returns-1 on Failure before PHP 5.1.0.
Example
<?php
Echo (Strtotime ("Now"));
Echo (Strtotime ("3 October 2005"));
Echo (Strtotime ("+5 hours"));
Echo (Strtotime ("+1 Week"));
Echo (Strtotime ("+1 Week 3 days 7 hours 5 Seconds"));
Echo (Strtotime ("Next Monday"));
Echo (Strtotime ("Last Sunday"));
?> output:

1138614504
1128290400
1138632504
1139219304
1139503709
1139180400
1138489200

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.