use*_*410 0 php date strtotime
我坚持可能是一个简单的问题,但我无法弄明白.
我想要做的是拿今天的日期2014-08-27然后将其更改为本月1日所以它将是2014-08-01
我知道我可以手动解析并做到这一点,但这似乎有点过分.我不熟悉使用日期,但我试过的4个例子中没有一个似乎有效.我想在获得新约会后将其转换为纪元时间
$todays_date = date('Y-m-d'); //current date 2014-08-27
Run Code Online (Sandbox Code Playgroud)
我的4次徒劳无益的尝试
echo "test1: " strtotime(date('Y-m-d', $todays_date)) . "<br />"; // returns -3600
echo "test2: " strtotime('Y-m-d', $todays_date) . "<br />"; // returns nothing
echo "test3: " strtotime('Y-m-01', $todays_date) . "<br />"; // returns nothing
echo "test4: " date('Y-m-01', $todays_date) . "<br />"; // returns nothing
Run Code Online (Sandbox Code Playgroud)
相对时间格式使这很容易:
echo (new DateTime('first day of this month'))->format('Y-m-d');
Run Code Online (Sandbox Code Playgroud)
要么
echo date('Y-m-d', strtotime('first day of this month'));
Run Code Online (Sandbox Code Playgroud)