我有以下格式DD的日期,d MM,YY(星期五,2011年10月21日)如何重新格式化它以日期格式(0000-00-00)存儲在MySQL數據庫?
Q
轉換日期格式
3
A
回答
3
使用date功能:
$time = strtotime("Friday, 21 October, 2011");
echo date("Y-m-d", $time);
所鏈接的頁面提供了可用的格式說明一個很好的說明, 和你可以看到預定義的datetime constants here。
Format Description ================================================================================ d Day of the month, 2 digits with leading zeros D A textual representation of a day, three letters j Day of the month without leading zeros l A full textual representation of the day of the week N ISO-8601 numeric representation of the day of the week S English ordinal suffix for the day of the month, 2 characters w Numeric representation of the day of the week z The day of the year (starting from 0) Week --------------------------------------------------------------- W ISO-8601 week number of year, weeks starting on Monday Month --------------------------------------------------------------- F A full textual representation of a month, such as January or March m Numeric representation of a month, with leading zeros M A short textual representation of a month, three letters n Numeric representation of a month, without leading zeros t Number of days in the given month Year --------------------------------------------------------------- L Whether it's a leap year o ISO-8601 year number. Y A full numeric representation of a year, 4 digits y A two digit representation of a year Time --------------------------------------------------------------- a Lowercase Ante meridiem and Post meridiem A Uppercase Ante meridiem and Post meridiem B Swatch Internet time g 12-hour format of an hour without leading zeros G 24-hour format of an hour without leading zeros h 12-hour format of an hour with leading zeros H 24-hour format of an hour with leading zeros i Minutes with leading zeros s Seconds, with leading zeros u Microseconds (added in PHP 5.2.2) Timezone --------------------------------------------------------------- e Timezone identifier (added in PHP 5.1.0) I Whether or not the date is in daylight saving time O Difference to Greenwich time (GMT) in hours P Difference to Greenwich time (GMT) with colon between h and m T Timezone abbreviation Z Timezone offset in seconds. Full Date/Time --------------------------------------------------------------- c ISO 8601 date (added in PHP 5) r » RFC 2822 formatted date U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
2
1
您的日期格式DD, d MM, yy
並不認同這一(Friday, 21 October, 2011
相符。也許你的意思date('l, d F, Y')
echo date("Y-m-d", strtotime(date('l, d F, Y')));
輸出
2011-10-08
相關問題
- 1. 轉換日期到MySQL日期格式
- 2. 轉換日期格式/加密日期
- 3. 日期格式轉換
- 4. 轉換爲日期格式
- 5. 轉換Unix日期格式
- 6. 轉換日期格式Perl
- 7. 轉換日期格式
- 8. Java日期格式轉換
- 9. 轉換日期格式
- 10. 轉換日期格式
- 11. 日期格式轉換javascript
- 12. PHP日期格式轉換
- 13. 轉換日期格式爲
- 14. 轉換日期格式
- 15. 轉換日期格式
- 16. 轉換日期格式SQL
- 17. Sql轉換日期格式
- 18. 轉換日期格式
- 19. Metl - 轉換日期格式
- 20. 日期格式轉換Ruby
- 21. 轉換.NET日期格式轉換爲JavaScript日期
- 22. 將文本日期格式轉換爲日期格式
- 23. 轉換任何日期格式的系統日期格式
- 24. 如何將日期日期轉換爲英文日期格式?
- 25. 將JavaScript日期格式轉換爲期望的PHP格式
- 26. MySQL導入CSV轉換日期格式
- 27. SQL - 轉換日期時間格式
- 28. Excel VBA - 日期格式轉換
- 29. 轉換的updated_at日期格式
- 30. PHP轉換日期時間格式
哦,對不起,這是一個actully JS格式... – santa
@santa確定。沒有問題。 – Mob