PHP / MySQL:从YYYY-MM-DD转换为DD月,YYYY? [英] PHP/MySQL: Convert from YYYY-MM-DD to DD Month, YYYY?
问题描述
我在MySQL表中有一个DATE列,它以这种格式表示日期:YYYY-MM-DD。
I have in a MySQL table a DATE column that represents the date in this format: YYYY-MM-DD.
我想从数据库中检索日期。使用PHP,但显示如下:DD月,YYYY。
I wanto to retrieve the date from the database using PHP but display it like this: DD Month, YYYY.
例如,从 2009-04-13到 2009年4月13日。
From '2009-04-13' to '13 April, 2009' for example.
女巫是最好的方法?? (我知道如何从数据库中获取日期。我只需要知道如何转换日期)。
Witch is the best way to do it?? ( I know how to get the date from the DB. I only need to know how to convert it)
我还需要用西班牙语显示月份名称。有一种方法可以不使用strplc或类似语言来翻译每个月?
I also need to display the month names in Spanish. There is a way to do it without translating each month using strplc or something like that??
我是编程新手,请详细介绍。
I'm new to programming, please be detailed.
谢谢!
推荐答案
请参阅 DATE_FORMAT()函数。我想这是您执行此操作的最佳方法。
Refer to DATE_FORMAT() function in MySQL. I guess that's the best way for you to do it.
此外,您可以执行以下操作:
Also, you can make this:
- Fetch your date from DB
- Use strtotime in PHP, to convert to unix time
- Then format the time using date.
通过使用date(),当您在PHP中设置语言环境时,您将能够获得西班牙语的月份名称。与 setlocale 。
By using date() you'll be able to get months names in Spanish when you set your locale in PHP with setlocale.
这篇关于PHP / MySQL:从YYYY-MM-DD转换为DD月,YYYY?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!