ホームページ  >  記事  >  バックエンド開発  >  PHP 時差を文字列に変換する_prompt_PHP チュートリアル

PHP 時差を文字列に変換する_prompt_PHP チュートリアル

WBOY
WBOYオリジナル
2016-07-21 15:24:21747ブラウズ

これを見る起来更加人性化,好吧,上代码

复制代码代码如下:

class timeAgo
{
static $timeagoObject;
プライベート$カサカサ;
プライベート $ユニット;
プライベート関数 __construct()
{
}
プライベート関数 __clone(){ }
パブリック静的関数 getObject()
{
if(! (self::$timeagoObject instanceof self) )
self::$timeagoObject = new timeAgo ();
self::$timeagoObject を返す;
}
プライベート関数 count_int($unix_C) // メイン関数
{
if(! (isset($unix_C) || is_numeric($unix_C)) )
return 'パラメータが見つかりません';
$d = time()-$unix_C ; // $d - UNIX 時差値
$d_int =(int)floor($d/60) ; // 最小単位 -- 分 unix/60
$this->unit = 0 ; // 分、時間、それとも日ですか?
if($d_int < 60){ // 1 時間の分 3600
$this->rustle = $d_int;
$this->単位 = 1;
}
else if($d_int < 720){ //1 日の時間 3600*12
$this->rustle = Floor($d_int/60);
$this->単位 = 2 ;
}
else if($d_int < 7200){ //10 日後の日 3600*12*10
$this->rustle = Floor($d_int/720);
$this->ユニット = 3 ;
}
else{
$this->カサカサ = $d ;
$this->ユニット = 4 ;
}
}
パブリック関数 Piece_str($C)
{
$this->count_int($C);
$u = '';
switch( $this->unit )
{
case 1:
$u = '分';
休憩;
ケース 2:
$u = '時間';
休憩;
ケース 3:
$u = '日';
休憩;
ケース 4:
$u = '';
休憩;
ケース 0:
return '申し訳ありませんが、時間の取得は失敗しました';
}
if($this->unit < 4)
{
if($this->rustle > 1)
return (string)$this->rustle.$u. の前';
else if($this->rustle == 1)
return (string)$this->rustle.$u.'ago';
else
return '今だけ';
}
}
/* 例: $ago = timeAgo::getObject();
* echo $ago->piece_str($unix);
* // 2 日前
*/
}
?>

www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/324289.html技術記事これを見て、さらに人間性を向上させ、好吧、上代コードを作成します: ?php class timeAgo { static $timeagoObject;プライベート $rustle;プライベート $unit;プライベート関数 __construct(...
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。