PHP转换月份
无论如何,是否可以将日期月份数字转换为字符串。
例如,1 转换为一月,2 =>二月等
我在下面尝试过
<?php echo date('F', strtotime($member['dob_month'])); ?>
但没有成功
is there anyway to convert date month numeric to string.
e.g. for 1 convert to January, 2 => February, etc
i tried below
<?php echo date('F', strtotime($member['dob_month'])); ?>
didnt work out
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
给定
$member['dob_month']
的值是一个从 1 开始的整数。Given the value of
$member['dob_month']
is an 1-based integer.您可以尝试使用 PHP 的
DateTime
类。注意:在
createFromFormat
中,使用 'm ' 如果月份有前导零,则为 'n' 如果没有。You can try to use PHP's
DateTime
class.Note: In
createFromFormat
, use 'm' if the month has leading zeros, 'n' if it doesn't.您的问题是
date()
需要为其第二个参数提供时间戳,并且strtotime($member['dob_month'])
如果 < code>$member['dob_month'] 是 1 到 12 之间的数字。您可以使用类似以下内容的内容:
Your problem is that
date()
needs a timestamp for it´s second parameter andstrtotime($member['dob_month'])
does not result in a meaningfull timestamp if$member['dob_month']
is a number from 1 to 12.You can use something like: