Home  >  Article  >  Backend Development  >  Format date

Format date

WBOY
WBOYOriginal
2016-07-25 09:11:21909browse
php format date
  1. function ShowDate($flag=0, $timestr=NULL)
  2. {
  3. // Get the day of the week
  4. $warr = array(
  5. "0" => Sunday,
  6. "1" => Monday,
  7. "2" => Tuesday,
  8. "3" => Wednesday,
  9. "4" => Thursday,
  10. "5" => Friday,
  11. "6" => Saturday
  12. );
  13. $i = date("w", $timeStamp);
  14. // Set Beijing time and get timestamp
  15. date_default_timezone_set('PRC');
  16. $timeStamp = NULL;
  17. if ($timestr)
  18. $timeStamp = strtotime($timestr );
  19. else
  20. $timeStamp = time();
  21. // Set the time display format
  22. $ret1 = date("Y year m month d day H:m:s", $timeStamp) . " " . $warr[ $i];
  23. $ret2 = date("Y-m-d H:m:s", $timeStamp) . " " . $warr[$i];
  24. $ret3 = date("y/m/d", $timeStamp) ;
  25. $ret = $ret1; // Return the first one by default
  26. if ($flag == 2)
  27. $ret = $ret2;
  28. else if ($flag == 3)
  29. $ret = $ret3;
  30. return $ret;
  31. }
Copy code
  1. function ShowDate($flag=0, $timestr=NULL)
  2. {
  3. // Get the day of the week
  4. $warr = array(
  5. "0" => Sunday,
  6. "1" => Monday,
  7. "2" => Tuesday,
  8. "3" => Wednesday,
  9. "4" => Thursday,
  10. "5" => Friday,
  11. "6" => Saturday
  12. );
  13. $i = date("w", $timeStamp);
  14. // Set Beijing time and get timestamp
  15. date_default_timezone_set('PRC');
  16. $timeStamp = NULL;
  17. if ($timestr)
  18. $timeStamp = strtotime($timestr );
  19. else
  20. $timeStamp = time();
  21. // Set the time display format
  22. $ret1 = date("Y year m month d day H:m:s", $timeStamp) . " " . $warr[ $i];
  23. $ret2 = date("Y-m-d H:m:s", $timeStamp) . " " . $warr[$i];
  24. $ret3 = date("y/m/d", $timeStamp) ;
  25. $ret = $ret1; // Return the first one by default
  26. if ($flag == 2)
  27. $ret = $ret2;
  28. else if ($flag == 3)
  29. $ret = $ret3;
  30. return $ret;
  31. }
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn