LoginSignup
1
0

More than 5 years have passed since last update.

[関数系] strtotime の細かい挙動を試してみた。

Last updated at Posted at 2018-10-14

概要

細かい挙動を試してみたかったので、それをただまとめているだけの記事。

環境

MacOS Sierra: 10.12.6

PHP 7.2.6 (cli) (built: May 25 2018 06:18:07) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.6, Copyright (c) 1999-2018, by Zend Technologies

内容

そもそも文字列じゃない
php > var_dump(date('Y-m-d H:i:s', strtotime(trim(2018-05-22))));
string(19) "1991-10-12 01:21:15"

php:文字列だけど、時刻はない その2
php > var_dump(date('Y-m-d H:i:s', strtotime(trim('2018-05-22'))));
string(19) "2018-05-22 00:00:00"

php > var_dump(date('Y-m-d H:i:s', strtotime('2018/05/22')));
string(19) "2018-05-22 00:00:00"
文字列で、
php > var_dump(date('Y-m-d H:i:s', strtotime(trim('2018-05-22T01:30'))));
string(19) "2018-05-22 01:30:00"
余計な空白が存在する文字列
php > var_dump(date('Y-m-d H:i:s', strtotime('2018-05-22T01:30 ')));
string(19) "2018-05-22 01:30:00"
空文字
php > var_dump(date('Y-m-d H:i:s', strtotime('')));
string(19) "1970-01-01 00:00:00"
null
php > var_dump(date('Y-m-d H:i:s', strtotime(null)));
string(19) "1970-01-01 00:00:00"
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0