• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

DateFormat PHP Class (php 处置日期)

php 搞代码 3年前 (2022-01-24) 20次浏览 已收录 0个评论

DateFormat PHP Class (php 处理日期)

代码:

<?phpclass FormatDate{    var $theTime;    function FormatDate($string)    {        	//Set constructor	        $this->theTime = $string;	}	//Returns numerical day	function Day() 	{	return date("j", $this->theTime); }		//Returns weekday	function WeekDay() 	{ 	return date("l", $this->theTime); }	//Returns full month	function Month()	{	return date("F", $this->theTime); }	//Returns short-hand month	function MonthShort() 	{ 	return date("M", $this->theTime); }	//Numeric for month	function MonthNum() 	{ 	return date("n", $this->theTime); }		//Full 4 digit year	function YearFull() 	{ 	return date("Y", $this->theTime); }	//Short 2 digit year	function Year() 	{ 	return date("y", $this->theTime); }	//24 Hr with Seconds	function MilitaryFull()	{	return date("G:i:s", $this->theTime); }	//24 Hr without Seconds	function Military()	{	return date("G:i", $this->theTime); }	//Standard with seconds	function StandardFull()	{	return date("g:i:s a", $this->theTime); }	//Standard without seconds	function Standard()	{	return date("g:i a", $this->theTime); }	//Date & Month & Year Full	function TextDate()	{	$string = $this->Month()." ".$this->Day()." ".$this->YearFu
本文来源gaodai.ma#com搞##代!^码@网*
搞gaodaima代码

ll(); return $string; } //Date & Month & Year Shorthand function TextDateShort(){ $string = $this->MonthShort()." ".$this->Day()." ".$this->Year(); return $string; } //Numerical Date & Month & Year function NumDate() { $string = $this->MonthNum()."/".$this->Day()."/".$this->YearFull(); return $string; } //Numerical Date & Month & Year Shorthand function NumDateShort() { $string = $this->MonthNum()."/".$this->Day()."/".$this->Year(); return $string; } //Month & Day Full function MonthDay() { $string = $this->Month()." ".$this->Day(); return $string; } //Month & Day Short function 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().'
';// 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().'
';// Aug 2 11echo $date->NumDate().'
';// 8/2/2011echo $date->NumDateShort().'
';// 8/2/11echo $date->MonthDay().'
';// August 2echo $date->MonthDayShort().'
';// Aug 2echo $date->TimeSince(time()).'
';// Less than an hour ago...

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:DateFormat PHP Class (php 处置日期)
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址