我将要使用DateTime类构建日历,我必须根据用户位置(DE,US,FR ..)来本地化日期名称。
// Date de debut
setlocale(LC_TIME, 'es_ES');
$today = new DateTime();
print_r($today->format('D'));
此摘要始终以英文打印日期,如何克服呢?
谢谢
答案 0 :(得分:1)
我找到了答案,很简单:
setlocale(LC_ALL, 'es_ES');
$today = new Datetime();
echo strftime("%A", $today->getTimestamp());
非常感谢您的帮助
答案 1 :(得分:0)
您可以使用javascript
<button onclick="userDate()">Try it</button>
<p id="test"></p>
<script>
function userDate() {
var d = new Date();
var n = d.toLocaleString(); //this is what you need
document.getElementById("test").innerHTML = n;
}
</script>