字符串转换的数字日期 [英] Numerical date to string conversion
问题描述
我使用以下代码转换格式为 mm / dd / yy
的日期,以显示 2008年11月19日
I am using the following code to convert a date in the format mm/dd/yy
to show November, 19, 2008
echo date('F d, Y', strtotime('{$month}/{$day}/{$year}'));
在我的数据库中,我有 $ month
, $ day
和 $ year
存储为 INT
。
In my database I have the values for $month
, $day
and $year
stored as an INT
.
当我将变量添加到date函数中时,输出错误。我有一个意想不到的日期。系统中的日期是 2/1/1977
,但输出值为 1969年12月31日
。
When I add the variables into the date function, the output is wrong. I am getting an unexpected date. The date I have in the system is 2/1/1977
but the output gives December 31, 1969
.
任何想法?
推荐答案
我认为问题是你的单引号在 strtotime
I think the problem isyour single quotes around the string in strtotime
中的字符串周围,单引号不会解析并放入变量值,它将正好是文字。你想使用双打
Single quotes wont parse and put in the variables value, it will be exactly that literal. you want to use doubles
$month = 1; $day = 2; $year = 2000;
echo date('F d, Y', strtotime("$month/$day/$year"));
echo ' {$month}/{$day}/{$year}'; //gives exactly whats between the single quotes
输出:
January 02, 2000 {$month}/{$day}/{$year}
编辑
EDIT
for($=0;$i<count($month);$i++)
echo date('F d, Y', strtotime($month[$i].'/'.$day[$i].'/'.$year[$i])) . '<br />';
这篇关于字符串转换的数字日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!