Heim  >  Artikel  >  Backend-Entwicklung  >  php格式化时间有关问题

php格式化时间有关问题

WBOY
WBOYOriginal
2016-06-13 13:52:40796Durchsuche

php格式化时间问题。
php5.1.2与MSSQL链接。
时间段是smalldatetime。
在库里看到的时间是:2007-04-06   21:23:00.000
用PHP显示出来的却是:2007   四月   6   21:23
请问,我要如何得到2007-04-06这样的时间格式?

------解决方案--------------------
date( 'Y-m-d ',strtotime($row[ 'somedate ']));
------解决方案--------------------
$s = "2007-04-06 21:23:00.000 ";
$t = explode( " ",$s);
echo $t[0];
------解决方案--------------------
$s = "somedate ";
$t = explode( " ",$s);

switch ($t[1])
case "一月 ":
$month= "01 ";
break;
case "二月 ":
$month= "02 ";
break;
case "三月 ":
$month= "03 ";
break;
case "四月 ":
$month= "04 ";
break;
case "五月 ":
$month= "05 ";
break;
case "六月 ":
$month= "06 ";
break;
case "七月 ":
$month= "07 ";
break;
case "八月 ":
$month= "01 ";
break;
case "九月 ":
$month= "09 ";
break;
case "十月 ":
$month=10;
break;
case "十一月 ":
$month=11;
break;
case "十二月 ":
$month=12;
break;
}

echo $t[0]. "- ".$month. "- ".$t[2];


练练手而已,不知道正确否....以上2种方式

------解决方案--------------------
这个是MSSQL的问题,他会调用系统的时间显示格式

你可以用strtotime转化为UNIX时间戳后,然后用date函数

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn