DateFormat PHP Class (php 处理日期)
代码:
<?phpclass FormatDate
{var $theTime;function FormatDate($string){//Set constructor$this->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); }//24 Hr with Secondsfunction MilitaryFull() { return date("G:i:s", $this->theTime); }//24 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 an 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;} }
}
实例:
$date = new FormatDate(time());echo $date->Day().'<br>';
// 2echo $date->WeekDay().'<br>';
// Tuesdayecho $date->Month().'<br>';
// Augustecho $date->MonthShort().'<br>';
// Augecho $date->MonthNum().'<br>';
// 8echo $date->YearFull().'<br>';
// 2011echo $date->Year().'<br>';
// 11echo $date->MilitaryFull().'<br>';
// 9:08:40echo $date->Military().'<br>';
// 9:08echo $date->StandardFull().'<br>';
// 9:08:40 amecho $date->Standard().'<br>';
// 9:08 amecho $date->TextDate().'<br>';
// August 2 2011echo $date->TextDateShort().'<br>';
// Aug 2 11echo $date->NumDate().'<br>';
// 8/2/2011echo $date->NumDateShort().'<br>';
// 8/2/11echo $date->MonthDay().'<br>';
// August 2echo $date->MonthDayShort().'<br>';
// Aug 2echo $date->TimeSince(time()).'<br>';
// 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);
格式: http://php.net/manual/en/function.date.php
-
format
characterDescription Example returned values Day --- --- d Day of the month, 2 digits with leading zeros 01 to 31 D A textual representation of a day, three letters Mon through Sun j Day of the month without leading zeros 1 to 31 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 English 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 of the year (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: 42 (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 01 through 12 M A short textual representation of a month, three letters Jan through Dec n Numeric representation of a month, without leading zeros 1 through 12 t Number of days in the given month 28 through 31 Year --- --- L Whether it's a leap year 1 if it is a leap year, 0 otherwise. o ISO-8601 year number. This has the same value as Y , except that if the ISO week number (W ) belongs to the previous or next year, 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 two digit representation of a year Examples: 99 or 03 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 000 through 999 g 12-hour format of an hour without leading zeros 1 through 12 G 24-hour format of an hour without leading zeros 0 through 23 h 12-hour format of an hour with leading zeros 01 through 12 H 24-hour format of an hour with leading zeros 00 through 23 i Minutes with leading zeros 00 to 59 s Seconds, with leading zeros 00 through 59 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 is 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 always negative, and for those east of UTC is 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, 21 Dec 2000 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 will be printed as-is. The Z format will always return 0 when using gmdate() .
Note :
Since this function only accepts integer timestamps the u format character is only useful when using the date_format() function with user based timestamps created with date_create() .
-
timestamp
-
The optional
timestamp
parameter is an integer Unix timestamp that defaults to the current local time if atimestamp
is not given. In other words, it defaults to the value of time() .
DateFormat PHP Class (php 处理日期)相关推荐
- php date class,DateFormat PHP Class (php 处置日期)
DateFormat PHP Class (php 处理日期) 代码:theTime = $string;}//Returns numerical dayfunction Day() {return ...
- dateformat java 格式_java Date日期类和SimpleDateFormat日期类格式
~Date表示特定的时间,精确到毫秒 ~构造方法: public Date()//构造Date对象并初始化为当前系统的时间 public Date(long date) //1970-1-1 0:0: ...
- Java如何清除日期_Java中关于日期的处理方法
(1)Date * Date: * 介绍是java.util包下的Date类,这个类是负责描述日期这类数据的. * Date主要是描述当前时间毫秒值对象. * 它中的很多方法不利于国际化,已经 ...
- java获取下一季末_java取当前周期、月初至月末、季度初至季度末日期。
常用日历操作辅助类 @author steven 2010-08-10 @email:qing.tan@iwode.com */ public class CalendarUtil { private ...
- java对日期的操作详解
import java.text.DateFormat; import java.text.ParseException; import java.text.ParsePosition; import ...
- Joomla2.5 JDate 时区日期运算
新版的JDate其实是PHP5内置日期类DateTime的扩展类,所以继承所有DateTime的方法,即可以把JDate当DateTime类来使用. 以下是得到前天的零时例子(PHP > 5.3 ...
- 大数据WEB阶段 后台和页面之间传递日期格式数据的400问题
后台和页面之间传递日期格式数据的400问题 一.分析 java中的日期格式是yyyy/MM/dd ,而浏览器中支持的格式是yyyy-MM-dd 二.后台向页面传递日期格式信息解决 用taglib标签引 ...
- 【Java语法】DateFormat时间格式转化、java.util.Date和java.sql.Date之间的相互转化
使用DateFormat,将时间与日期相互转换 import java.text.DateFormat; import java.text.ParseException; import java.te ...
- java 查询日期行列转换_java中日期格式的转换和应用
java中主要有3个类用于日期格式转换 DateFormat .SimpleDateFormat.Calendar SimpleDateFormat函数的继承关系: java.lang.Obje ...
最新文章
- maven install 报错 source 1.5 中不支持 lambda 表达式
- 在IE中测试调用Web Service
- 使用OKHttp3实现下载(断点续传、显示进度)
- rop检查_注意!这几类人一定要定期检查眼底!
- java面向对象-------类属性和方法,不同类之间调用
- [ZJOI2014] 星系调查(树上差分 + 数学推式子)
- C++:05---class和struct
- 计算机原理语言方框图,计算机原理整理原版1.10.docx
- Android AlarmManager广播接收器和服务
- 《那些年啊,那些事——一个程序员的奋斗史》四
- Python基础教程,Python入门教程(非常详细)
- poi合并单元格内容重复,只保留一个
- 如何提高机器学习模型预测准确率
- 计算机指令执行过程详解
- 后盾网mysql_后盾网MySQL数据库视频图文详细教程资源推荐
- 帝国cms没有标题图片就显示默认图片
- 道格拉斯普克算法(简化线段点)
- vue keys detected: '1111'. This may cause an update error.
- 瑞萨can入门书学习三
- 最新软件外包网站有哪些?
热门文章
- 60 MM配置-后勤发票校验-设置重复发票检查
- python中main方法的用法_python __main__和__init__正确用法
- Numpy 之shape manipulation
- 【pytorch】torch.cuda.empty_cache()==>释放缓存分配器当前持有的且未占用的缓存显存
- vue设置isactive_vue 绑定样式的几种方式
- phpcmsV9发布文章后无法删除?后台找不到了?从phpmyadmin数据库删除吧!
- elementUI解决el-checkbox自定义样式、@change样式的失效 等bug - 代码示例
- js - 让 git 上 Mint-UI 的例子跑起来 - 方法大全
- Discuz素材资源下载官网门户+自带论坛 整站源码+带后台+带数据库
- 得推B2B2C商城源码v4.1