The initialization statement for adding time to the program: "date_default_timezone_set (" asia/shanghai ");
Definition and usage
The date_default_timezone_set () function sets the default timezone used by all date/time functions.The
(1) dateUsage: date (format, [time]);If there is no time parameter, the current time is used. The format is a string. The following characters have special meanings:U is replaced by the number of seconds since the start time (like January 1, 1970 ).
Today, let's take a look at the time difference between two time points in php. Now we use data directly, and the strtotime and time functions are implemented. If you need them, please refer to them.
The requirement for this example is as follows.
This article mainly sorts out the related content about the date and time calculation of php, which involves comprehensive knowledge points. If you are interested, please refer to it.
This article mainly sorts out the related content about the date
How to use this class? See the following demo:Copy codeThe Code is as follows:$ Temptime = time ();Echo strftime ("% Hh % M % A % d % B", $ temptime );$ Date = new DateAccount ();$ Temptime = $ date-> DateAdd ("n", 50, $ temptime );Echo " ";Echo
This article provides a regular expression to verify whether a date is a regular date format. The first is a normal date verification, which is passed safely. The date format in section 2 is incorrect, so the output date is invalid. This article
1. Get the current Time method date ()It's simple, that's the way to get time,The format is: Date ($format, $timestamp),Format is formatting- requiredTimestamp is timestamp – The parameter can be filled.Like what:echo Date (' YMD '), Output: 2012032
The current time is increased by one day: ecchodate (Y-m-d, strtotime (+ 1day) the current time is increased by January: strtotime (+ 1 month) the current time is increased by one year: strtotime (+ 1 year) current time increase by one second:
Time () is a number in PHP. This number indicates how many seconds have elapsed since. It's strange.However, this facilitates computing,Find that the previous day is time ()-60*60*24;Find that the time of the previous year is time () *
Here we will introduce the differences between the date functions in php. Here we mainly talk about the differences in the usage of date and gmdate. If you need them, please refer to them.
Date-format a local time/date
The date/time function allows
This article is to share the content of PHP in the date () and time () function of the application, the need for friends can refer to
1, the current timestamp (unit: seconds)
Description: The time () function returns the number of seconds of the
Date_default_timezone_set (' PRC ');
/**
* To find a date after a certain number of days from a certain date,
* Exclude Saturday Sundays and holidays
* @param $start Start date
* @param $offset days Elapsed
* @param $exception exceptions for
PHP code
Returns the first day of the specified month function get_the_month_first_day_str ($theyear, $themonth) { return date ("Y-m-d", mktime (0, 0, 0, $themonth, 1, $theyear)); } Returns the last day of the specified month function get_
In php, if we get another date by adding or subtracting a few days from a date, we will use two instances to indicate that the time is converted to the timestamp by strtotime and mktime and then processed, if you need it, check it out. Example:
Format date () and gmdate () in PHP. The datetime function allows you to extract and format the date and time on the server. These functions depend on the local settings of the server. First, we will introduce the time () function: the time ()
The date () function formats the local date and time and returns the formatted date string.
The following is an example of the parameters of the date () function, as shown in the code below
The code is as follows:
Format displayed: Year-month-day
PHP provides functions that can easily convert various forms of a date to a timestamp, which is mainly:
Strtotime (): Resolves the datetime description of any English text to a timestamp.
Mktime (): Gets the timestamp from the date.
(1) Date
Usage: Date (format, [time]);
If there is no time parameter, the current time is used. The format is a string in which the following characters have special meanings:
U is replaced by the number of seconds since a starting time (as if it
Let's look at some of the usage and basic details of the date () function in PHP, as you can see here.
Date function usage
The code is as follows
Copy Code
Date ($t);
The format is as follows:
Format displayed:
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.