超strtotime() は当初ウケ狙いで strtoti.me というドメインだったんですが、なんやかんやありまして別のものに変わりました。

PHPMatsuri 2012 というイベントに参加して作りました。
これは何
PHP の strtotime() では対応できない書式の日付を正規化して
JSON で返すサービスです。
strtotime はできる子
strtotime はこういう関数で
英文形式の日付を Unix タイムスタンプに変換する
なかなかできる子です。
PHP マニュアルのサンプルはこうなってるけど
echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";
こういうのもいけますね。
//区切りなしの日付でもいける
echo strtotime("20121104");
//1351954800
//西暦下2桁で書くと日付と時刻の両方に取っちゃうけど一応いける
echo strtotime("121104");
//1351998664 = 2012/11/04 12:11:04
//日本語でよく使うスラッシュ区切りもいける
echo strtotime("2012/11/04");
//1351954800
strtotime が苦手なこと
ただしこういうのが苦手です。
//ドット区切りは苦手
echo strtotime("2012.11.04");
//false
//漢字は苦手
echo strtotime("2012年11月4日");
//false
//元号も苦手
echo strtotime("H24-11-04");
//1730649600 が返ってくるけど
//これは 2024-11-04 だ。
そこで、超strtotime()
http://strtoti.me/ の後に日付をつけてアクセスすると
正規化された情報を JSON で返します。
{
"year": 1974,
"month": 4,
"day": 13,
"mmdd": "0413",
"timestamp": 135010800
}
JSONP 対応
http://strtoti.me/S49.04.13?callback=birthday
birthday({"gen":"\u662d\u548c
","year":1974,"month":4,"day"
:13,"mmdd":"0413","gen_year":49,"show_year":"\u662d\u548c4
9\u5e74","timestamp":135010800})
漢数字対応
{
"year": 2012,
"month": 11,
"day": 4,
"mmdd": "1104",
"timestamp": 1351954800
}
元号対応
{
"gen": "平成",
"gen_year": 1,
"show_year": "平成元年",
"year": 1989,
"month": 1,
"day": 8,
"mmdd": "0108",
"timestamp": 600188400
}
元号バリデーションつき
{
"gen": "大正",
"gen_year": 20,
"show_year": "大正20年",
"year": 1931,
"month": 5,
"day": 5,
"mmdd": "0505",
"notice": "大正は15年までです。",
"timestamp": -1220086800
}
{
"gen": "昭和",
"gen_year": 64,
"show_year": "昭和64年",
"year": 1989,
"month": 1,
"day": 31,
"mmdd": "0131",
"notice": "昭和64年は1月7日までです。",
"timestamp": 602175600
}
閏年バリデーションつき
{
"show_year": "2013年",
"year": 2013、
"month": 2,
"day": 29,
"mmdd": "0229",
"notice": "2013年の2月は28日までです。",
"timestamp": 1362063600
}
自問自答
Q: 日付だけ? 時刻は?
最初にも書きましたけど
これは PHPMatsuri in 福岡で作ったものです。
いまこの記事もそのイベント会場で書いてます。
日付にも対応しようと思ったら初日の夜になってしまい
これは日付とか言ってる場合じゃないなと思ったので
ラーメンを食べに行きました。
帰ったら対応しますたぶん。
Q: 何に使うの?
各自で決めてください。