Php strftime function and strftime instance tutorial

Source: Internet
Author: User
Tags month name php tutorial string format strlen time and date

Format the time and/or date by region. The setting of the current language environment for the month and the day of the week and other language-related strings is as follows: setlocale ().

Not all conversion specifiers support your C library. In this case, they will notStrftime. In addition, not all platforms support negative timestamps, so your date range may be limited to not earlier than the Unix era. This means that, like % e, % T, % R and, % d (or other)-and the date before January 1-1970 will not work on Windows, some Linux releases, and other operating systems. For Windows systems, a complete overview of supported conversion specifiers can be found in

The following is a string format parameter.
Day --- www.111cn.net ---
% 1 day short for Sun sat's text expression
% Airport management bureau full text representation of a day from Sunday to Saturday
% & ETH; double-digit months (with leading zero) 01 to 31
% & Eacute; the month of the day, the space from the previous digit to 31
Reference the year of % j Day, 3 leading 0 001 to 366 bits
% U (expressed as Monday through ISO-8601) on this Monday (although 7 (Sunday)
% Watt number indicates the week 0 Sunday to 6 (Saturday)
Week ------
% & Uuml; the first Sunday of each year is the 13-13-year full week of the first week () starting from the given weeks ()
% V passed ISO-8601: the number of weeks at the end of the year in 1988, first of all, the first week of the year, at least four Sundays and Monday start from 01 to 53 of a week (53 of them are overlapping weekly accounts)
The number of "West Australia %" indicates the week of the Year. The first Monday indicates the 46 day of the first week and the start of the 46 week of the first year ()
One month ------
% B is abbreviated based on the month name, through the site January 12 month
% B: based on the names of all months, the site is from January 1, January to January 1, December.
% H abbreviation of the month name, based on the region settings (passed 12%, alias 2) 1
Two digits % meters represent 01 (January) to 12 (December) of the month)
Year ------
% C two centuries (divided by the double-digit representativeness in 100, rounded up) is 20th century 19
Two double-digit representation of % G passed ISO-8601: 1988 standard (see % V) example: 6 weeks, January 09
Take % of all 4-digit versions of % G as an example: For Week 2008
%, For example, the first two digits represent the Year: 2009, 1979 79
%, Which represents the year as an example from the first four digits: January 1, 2038
Time ------
% H two-digit number indicates 00 to 23 hours in 24-hour format
To 12%, my two 12-hour format represents zero one-hour
% L (lower-case L ') in 12-hour format, with the first 1 to 12 digits of space
% Male's double-digit representative 00-59 minutes
% P upper case 'am' or 'Premier 'based on the given time example: 12:31 A.M., PM
In the lower case of % P, 'I' or 'time' is based on the given time example: 12:31 A.M., PM
Example of "% 1: % male: % S % P" in the same region: 09:34:17 is 21:34:17 P.M.
Example of "% H: % M" in the same format as "% M": 12:35 A.M., four o'clock P.M.,
%, The second two 00 digits represent 59
Example: 09:34:17 P.M., 17 seconds
% × The representative time of the preferred region does not have a date, for example, 03:59:16 or 15:59:16
% Percent whether it is from the UTC time zone or abbreviation (offset depends on the operating system) for example:-0500 or eastern time us east time
% Region time zone offset/abbreviation selection is no longer given by % (depends on the operating system) example:-0500 or eastern time us east time
Time and date stamp ------
% & Ccedil; preferred date and timestamp based on the local example: Tuesday February 5 00:45:10 2009 February 4, 2009 12:45:10 A.M.
%, For example, "% meters of D/% d/% Y": 02/05/09 is February 5, 2009
%, Which is the same as "% female Y % meters-% D" class (commonly used database tutorial day stamp): February 5, 2009
% S Unix epoch timestamp (depending on the time as the September 10 () function) example: 305815200,1979 08:40:00 A.M. same
% × The cornerstone of the representative region of the preferred date, not subject to time, for example: 02/05/09, February 5, 2009
Miscellaneous ------
% N line breaks ("N )---
% T tab ("t )---
% Percentage of a text character ("% ---


This parameter can contain a maximum of 1023 characters.

Let's take a look.StrftimeInstance

<? Php Tutorial
Setlocale (LC_TIME, "C ");
Echo strftime ("% ");
Setlocale (LC_TIME, "fi_FI ");
Echo strftime ("in Finnish is % ,");
Setlocale (LC_TIME, "fr_FR ");
Echo strftime ("in French % A and ");
Setlocale (LC_TIME, "de_DE ");
Echo strftime ("in German % .");
?>

<? Php
$ Ts = strtotime ("4 Nov 2009 ");
Echo strlen (strftime ("%-e", $ ts), ""; // "1" (no padding)
Echo strlen (strftime ("% e", $ ts), ""; // "2" (space padded)
?>

Instance 3

<? Php
// Date string
$ Timestamp = strftime ("% Y-% m-% d % H: % M: % S % Y ");

// From this string ($ timestamp) can we print
Echo strftime ("% a % d % B % H: % M: % S % Y", strtotime ($ timestamp). "<br/> ";
Echo strftime ("% a % d % B % H: % M", strtotime ($ timestamp). "<br/> ";
Echo strftime ("% Y-% m-% d % H: % M: % S", strtotime ($ timestamp). "<br/> ";
Echo strftime ("% Y-% m-% d % H: % M", strtotime ($ timestamp). "<br/> ";
Echo strftime ("% Y-% m-% d", strtotime ($ timestamp). "<br/> ";
Echo strftime ("% a % d % B % Y", strtotime ($ timestamp). "<br/> ";

/* And it will output

Wed 20 May at 15:53:40 2009
Wed 20 May 15: 53
15:53:40

2009-05-20
Wed 20 May 2009

*/
?>

AboutStrftimeInstance 5

Function calculateFiscalYearForDate ($ inputDate, $ fyStart, $ fyEnd ){
$ Date = strtotime ($ inputDate );
$ Inputyear = strftime ('% Y', $ date );
       
$ Fystartdate = strtotime ($ fyStart. $ inputyear );
$ Fyenddate = strtotime ($ fyEnd. $ inputyear );

If ($ date <$ fyenddate ){
$ Fy = intval ($ inputyear );
} Else {
$ Fy = intval ($ inputyear) + 1 );
    }
   
Return $ fy;
   
}

// My fiscal year starts on July, 1 and ends on June 30, so...
Echo calculateFiscalYearForDate ("5/15/08", "7/1", "6/30 ");
/// Returns 2008

Echo calculateFiscalYearForDate ("12/1/08", "7/1", "6/30 ");

Reprinted on this site, indicating from www.111cn.net. Thank you for your cooperation.

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.