DateFormat php Class (php disposition date)

Source: Internet
Author: User
Tags dateformat iso 8601 iso 8601 date
DateFormat php Class (PHP processing date)

Code:

 Thetime = $string;} Returns numerical dayfunction Day () {return date ("J", $this->thetime);} Returns weekdayfunction WeekDay () {return date ("L", $this->thetime);} Returns full Monthfunction Month () {return date ("F", $this->thetime);} Returns Short-hand monthfunction Monthshort () {return date ("M", $this->thetime);} Numeric for Monthfunction Monthnum () {return date ("n", $this->thetime);} Full 4 digit yearfunction yearfull () {return date ("Y", $this->thetime);} Short 2 digit yearfunction year () {return date ("Y", $this->thetime);} + Hr with Secondsfunction militaryfull () {return date ("G:i:s", $this->thetime);} Hr without secondsfunction Military () {return date ("G:i", $this->thetime);} Standard with Secondsfunction Standardfull () {return date ("G:i:s a", $this->thetime);} Standard without secondsfunction standard () {return date ("G:i a", $this->thetime);} Date & Month & Year Fullfunction TextDate () {$string = $this->month (). " ". $this->day ()." ". $this->yearfull (); return $string;} Date & Month & Year Shorthandfunction Textdateshort () {$string = $this->monthshort (). " ". $this->day ()." ". $this->year (); return $string;} Numerical Date & Month & yearfunction numdate () {$string = $this->monthnum (). " /". $this->day ()." /". $this->yearfull (); return $string;} Numerical Date & Month & Year Shorthandfunction Numdateshort () {$string = $this->monthnum (). " /". $this->day ()." /". $this->year (); return $string;} Month & Day Fullfunction MonthDay () {$string = $this->month (). " ". $this->day (); return $string;} Month & Day Shortfunction Monthdayshort () {$string = $this->monthshort (). " ". $this->day (); return $string;} function timesince ($old _stamp) {$difference = $this->thetime-$old _stamp; $loop = True;while ($loop) {if (Round ($ difference/3153600, 2) >= 1) {return "over a year ...";} ElseIf (Round ($difference/2592000, 2) >= 2) {return "over". Round ($difference/2592000,0). "Months ago ..."; }elseif (Round ($difference/2592000, 2) >= 1.20) {return "over a month ago ...";} ElseIf (Round ($difference/604800, 2) >= 2) {return "over". Round ($difference/604800,0). "Weeks ago.";} ElseIf (Round ($difference/604800, 2) >= 1.20) {return "over a week ago:";} ElseIf (Round ($difference/86400, 2) >= 1.9) {return "over a few days ago ...";} ElseIf (Round ($difference/3600, 2) >= 3) {return "Just a few hours ago:";} ElseIf (Round ($difference/3600, 2) >= 8) {return "About half a day ago ...";} ElseIf (Round ($difference/3600, 2) < 1) {return "Less than a hour ago ...";} ElseIf (Round ($difference/86400, 2) < 1.9) {return "about a day ago ...";} ElseIf (Round ($difference/86400, 2) < 6) {return "Less than a week ago ...";} ElseIf (Round ($difference/604800, 2) < 1.20) {return "about a week ago:";} ElseIf (Round ($difference/2592000, 2) < 1.20) {return "about a month ago ...";} else{return "Error";} $loop = false;}}}
?

Instance:

$date = new FormatDate (Time ()), Echo $date->day (). '
';//2echo $date->weekday (). '
';//Tuesdayecho $date->month (). '
';//Augustecho $date->monthshort (). '
';//Augecho $date->monthnum (). '
';//8echo $date->yearfull (). '
';//2011echo $date->year (). '
';//11echo $date->militaryfull (). '
';//9:08:40echo $date->military (). '
';//9:08echo $date->standardfull (). '
';//9:08:40 Amecho $date->standard (). '
';//9:08 Amecho $date->textdate (). '
';//August 2 2011echo $date->textdateshort (). '
';//2 11echo $date->numdate ().
';//8/2/2011echo $date->numdateshort (). '
';//8/2/11echo $date->monthday (). '
';//August 2echo $date->monthdayshort (). '
';//2echo $date->timesince (Time ()). '
';//less than an hour ago ...

?

DateFormat class Documentation

Initialize class
$date = new FormatDate (time ());

Numerical Day
$date->day ();

Text Day
$date->weekday ();

Month (Full)
$date->month ();

Month (short)
$date->monthshort ();

Month (numerical)
$date->monthnum ();

Year (full)
$date->yearfull ();

Year (short)
$date->year ();

Military (Seconds)
$date->militaryfull ();

Military (No seconds)
$date->military ();

Standard (full)
$date->standardfull ();

Standard
$date->standard ();

Text Date (full)
$date->textdate ();

Text Date (short)
$date->textdateshort ();

Numerical Date (full)
$date->numdate ();

Numerical Date (short)
$date->numdateshort ();

Month and Day (full)
$date->monthday ();

Month and Day (short)
$date->monthdayshort ();

Time Since
$date->timesince ($timestamp);

?

Format: http://php.net/manual/en/function.date.php

format Character Description Example returned values
Day --- ---
D Day of the month, 2 digits with leading zeros to
D A textual representation of a day, three letters Mon through Sun
J Day of the month without leading zeros 1 to
l (lowercase ' l ') A full textual representation of the day of the week Sunday through Saturday
N ISO-8601 numeric representation of the Day of the week (added in PHP 5.1.0) 1 (for Monday) through 7 (for Sunday)
S 中文版 ordinal suffix for the day of the month, 2 characters St, nd, Rd or th. Works well with J
W Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday)
Z The day's (starting from 0) 0 through 365
Week --- ---
W ISO-8601 Week number of year, weeks starting on Monday (added in PHP 4.1.0) Example: (the 42nd Week in the year)
Month --- ---
F A full textual representation of a month, such as January or March January through December
M Numeric representation of a month, with leading zeros through
M A short textual representation of a month, three letters Jan through Dec
N Numeric representation of a month, without leading zeros 1 through
T Number of days in the given month through
Year --- ---
L Whether it ' s a leap year 1 If it is a leap year, 0 otherwise.
O ISO-8601 year number. This have the same value as Y, except if the ISO week number (W) belongs to the previous or next yea R, that year is used instead. (added in PHP 5.1.0) Examples: 1999 or 2003
Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003
Y A digit representation of a year Examples: or
Time --- ---
A lowercase Ante meridiem and Post Meridiem am or pm
A Uppercase Ante Meridiem and Post Meridiem AM or PM
B Swatch Internet Time through 999
G 12-hour format of an hour without leading zeros 1 through
G 24-hour format of an hour without leading zeros 0 through
H 12-hour format of an hour with leading zeros through
H 24-hour format of an hour with leading zeros xx through
I Minutes with leading zeros xx to
S Seconds, with leading zeros xx through
U Microseconds (added in PHP 5.2.2) Example: 654321
Timezone --- ---
E Timezone identifier (added in PHP 5.1.0) Examples: UTC, GMT, atlantic/azores
I (capital i) Whether or not the date was in daylight saving time 1 If daylight saving time, 0 otherwise.
O Difference to Greenwich time (GMT) in hours Example: +0200
P Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3) Example: +02:00
T Timezone abbreviation Examples: EST, MDT ...
Z Timezone offset in seconds. The offset for TimeZones west of UTC is all negative, and for those east of UTC are always positive. -43200 through 50400
Full Date/time --- ---
C ISO 8601 Date (added in PHP 5) 2004-02-12t15:19:21+00:00
R ?? RFC 2822 Formatted Date Example: Thu, Dec 16:01:07 +0200
U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) See also Time ()

Unrecognized characters in the format string would be printed as-is. The Z format would always return 0 when using gmdate ().

Note:

Since This function only accepts integer timestamps the u format character are only useful when using t The He date_format () function with the user based timestamps created with date_create ().

timestamp

The optional timestamp parameter is aninteger Unix timestamp, defaults to the currentlocal time if a timestamp are not given. In otherwords, it defaults to the value of Time ().

?

?

?

?

  • Related Article

    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.