PHP出力時差関数コード_PHPチュートリアル

WBOY
リリース: 2016-07-21 15:13:13
オリジナル
908 人が閲覧しました

PHP出力時差関数

コードをコピー コードは次のとおりです:

date_default_timezone_set('PRC') //デフォルトのタイムゾーン
echo "Today:",date("Y-m-d",time(); ),"
";
echo "今日:",date("Y-m-d",strtotime("2008 年 6 月 18 日")),"
";
echo "昨日:",date("Y-m-d"; ",strtotime( "-1 日")), "
";
echo "明日:",date("Y-m-d",strtotime("+1 日")), "
";
echo "1 週間後 :",date("Y-m-d",strtotime("+1 週間")), "
"
echo "1 週間、2 日、4 時間 2 秒後:",date ("Y-m-d G:H:s ",strtotime("+1 週間 2 日 4 時間 2 秒")), "
"
echo "来週の木曜日:",date("Y-m-d",strtotime(")来週の木曜日")), "
";
echo "先週の月曜日:".date("Y-m-d",strtotime("最後の月曜日"))."
";
echo "1 か月前: ".date("Y-m-d ",strtotime("先月"))."
";
echo "1 か月後:".date("Y-m-d",strtotime("+1 か月"))."
";
echo "10 年後:".date("Y-m-d",strtotime("+10 year"))."
";
?>

PHP を学習するとき、現在の前後の特定期間の日付を取得することがよくあります。収集されたので、展開して充実させることもできます
コードをコピーします コードは次のとおりです:

//曜日 (1-7) を取得します
function GetWeek($回)
{
$res = date('w', strtotime($times));
if($res==0)
$res=7;
return $res;
}
//時間を取得します今日の時間
function GetTime($times)
{
$res = date('H:i', strtotime($times));
return $res;
}
//今すぐ数か月後の時間を取得します
function GetMonth($Month,$type='l' )
{
if(!strcmp($type,'b'))
$res=date("Y-m-d H:i:s",strtotime("-$Month months) "));
if(!strcmp($ type,'l'))
$res=date("Y-m-d H:i:s",strtotime("+$Month months"));
return $res;
}
//現在時刻を取得します
function GetCurrentDateTime( )
{
$res=date("Y-m-d H:i:s",time());
return $res;
}
// or より前の時刻を取得します現在の時間間隔の後
function GetDiffHours($hours ,$type='l')
{
if(!strcmp($type,'b'))
$res=date("Y-m-d H:i:s", strtotime("-$時間時"));
if(!strcmp($type,'l'))
$res=date("Y-m-d H:i:s",strtotime("+$時間時")) ;
return $res
}
// 間隔の前後の時間 (分単位)
function GetDiffMinute($Minute,$type='l')
{
if(!strcmp($type,'b'))
$res=date("Y-m-d H:i: s",strtotime("-$Minute 分"));
if(!strcmp($type,'l'))
$res=date("Y-m-d H: i:s",strtotime("+$Minute 分 "));
return $res;
}
//秒単位の間隔の前後の時間
function GetDiffSec($sec,$type='l')
{
if(!strcmp($type,'b' ))
$res=date("Y-m-d H:i:s",strtotime("-$sec Second"));
if(!strcmp($type, 'l'))
$res=date("Y-m-d H:i:s",strtotime("+$sec 秒"));
return $res;
//間隔の前後何週間かfunction GetDiffWeek($Week,$type='l')

{
if(!strcmp($type,'b'))
$res=date("Y-m-d H :i:s",strtotime("-$Week 週"));
if(!strcmp($type,'l'))
$res=date("Y-m-d H:i:s",strtotime(" + $Week 週"));
return $res;
}
// 日間の時間
function GetDiffDays($days,$type='l')
{
if(!strcmp($type, 'b') )
$res=date("Y-m-d H:i:s",strtotime("-$days day"));
if(!strcmp($type,'l'))
$res=date ("Y-m-d H :i:s",strtotime("+$days day"));
return $res;
}
//数年間隔の前後の時間
function GetDiffyears($year,$type=' l' )
{
if(!strcmp($type,'b'))
$res=date("Y-m-d H:i:s",strtotime("-$year year"));
if(!strcmp ($ type,'l'))
$res=date("Y-m-d H:i:s",strtotime("+$year year"));
return $res;

www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/326523.html技術記事 PHP 出力時差関数のコピーコードは次のとおりです: ?php date_default_timezone_set('PRC'); //デフォルトのタイムゾーン echo "Today:",date("Y-m-d",time()),"br"; :",date ("Y-m-d",strt...
)
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!