用PHP转换漂亮的日期

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用PHP转换漂亮的日期相关的知识,希望对你有一定的参考价值。

This takes a date like so: Sat, 08 Jan 2011 from a database and allows you to use it in your code. For example if you wanted to work out a week from Sat, 08 Jan 2011 it can be done with ease. I created this for a project i am currently working on. There maybe an easier way to deal with this problem but its works so enjoy!
  1. <?php
  2.  
  3. function scheduleGameForNextWeek($date)
  4. {
  5. $day = substr($date,5,-9);
  6. $month = substr($date,-8,3);
  7. $year = substr($date, -4);
  8.  
  9. $month = strtolower($month);
  10.  
  11. switch($month)
  12. {
  13. case "jan":
  14. $month = "01";
  15. break;
  16. case "feb":
  17. $month = "02";
  18. break;
  19. case "mar":
  20. $month = "03";
  21. break;
  22. case "apr":
  23. $month = "04";
  24. break;
  25. case "may":
  26. $month = "05";
  27. break;
  28. case "jun":
  29. $month = "06";
  30. break;
  31. case "jul":
  32. $month = "07";
  33. break;
  34. case "aug":
  35. $month = "08";
  36. break;
  37. case "sep":
  38. $month = "09";
  39. break;
  40. case "oct":
  41. $month = "10";
  42. break;
  43. case "nov":
  44. $month = "11";
  45. break;
  46. case "dec":
  47. $month = "12";
  48. break;
  49. default:
  50. $month = "00";
  51. break;
  52. }
  53.  
  54. return $newDate = date('F jS Y', mktime(0,0,0,$month,$day+7,$year));
  55. }
  56.  
  57. $date = "Sun, 9 Jan 2011";
  58.  
  59. echo $newDate = scheduleGameForNextWeek($date);
  60.  
  61. ?>

以上是关于用PHP转换漂亮的日期的主要内容,如果未能解决你的问题,请参考以下文章

超实用的php代码片段

php怎么将指定日期转换为时间戳?

PHP必用代码片段

PHP Wordpress更好的日期片段

PHP时间戳慢一个小时

php怎么将指定日期转换为时间戳