2017-02-21 5 views
-1

私はこのコードで文字列fromatedの日付に月を追加してい:のstrtotime()広告の月変化の分

$str ="2017-01-29 14:22:57"; 
$effectiveDate = strtotime("+1 months", strtotime($str)); 
echo "<br>"; 
echo date('Y-m-d h:m:s',strtotime($str)); 
echo "<br>"; 
echo date('Y-m-d h:m:s',$effectiveDate); 

出力されています:

2017-01-29 02:01:57 
2017-03-01 02:03:57 

私は疑問に思って、なぜです少し変わった?毎月1分の変化があるようです。

+4

「m」=> *の場合はhttp://php.net/manual/en/function.date.php m \t **月の数値表現先行ゼロ付き\t 01〜12 * - あなたが望む**分**のための「私」。 'h:m:s'の代わりに' h:i:s'を実行するのがその理由です。 –

+0

ちょうどヒント: '$ effectiveDate = strtotime(" $ str +1 months ");' – JustOnUnderMillions

+0

も参考にしてください:http://php.net/manual/de/class.datetime.php#datetime.constants .types – JustOnUnderMillions

答えて

2

私はこれをコミュニティのwikiとしてポップアップします。私はこれのために代理人を望んでいないし、それから何かが作られるべきではない。先頭にゼロとのマニュアルhttp://php.net/manual/en/function.date.php

m =>メートル数値表現から

、12

01〜あなたがためiをしたいです。 h:m:sの代わりにh:i:sを実行するのがその理由です。

+0

@sanjihanプラス、あなたは "m"はある意味では完全に論理的な "分"を意味すると思ったかもしれません。 –

1
あなたは時間として書式設定している

echo date('Y-m-d h:i:s', $effectiveDate); 

詳細については、date documentationを参照してください:あなたがしたいと思うのタイムスタンプを持つように、秒:月。

関連する問題