php 获取给定日期的月份
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3474315/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:53:18 来源:igfitidea点击:
Get month of a given date
提问by nullpointerexception
Get month of a given date which is stored in a PHP time variable in 'Y-m-d' format
获取以“Ymd”格式存储在 PHP 时间变量中的给定日期的月份
回答by Bill Karwin
$date = "2010-08-12";
$d = date_parse_from_format("Y-m-d", $date);
echo $d["month"];
回答by Adnan
$date = "2010-10-10";
echo date("m", strtotime($date))?>
回答by vikmalhotra
$parts = explode('-',$your_date_variable_in_php);
$month = $parts[1];
回答by Your Common Sense
is it really stored in PHP? Not in some database?month(datefield)can do it in mysql query for example
它真的存储在PHP中吗?不是在某个数据库中?month(datefield)例如可以在 mysql 查询中完成
回答by Awan
echo date("F", strtotime("2010-08-13"));
回答by vtorhonen
You can use date()and strtotime():
您可以使用date()和strtotime():
<?php
$date = "2010-08-13";
echo date("m",strtotime($date))."\n";
?>

