CDate.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * FecShop file.
  4. *
  5. * @link http://www.fecshop.com/
  6. * @copyright Copyright (c) 2016 FecShop Software LLC
  7. * @license http://www.fecshop.com/license/
  8. */
  9. namespace fec\helpers;
  10. use Yii;
  11. /**
  12. * @author Terry Zhao <2358269014@qq.com>
  13. * @since 1.0
  14. */
  15. class CDate
  16. {
  17. # 1.得到时间
  18. public static function getCurrentDateTime(){
  19. return date('Y-m-d H:i:s');
  20. }
  21. # 2.得到时间
  22. public static function getCurrentDate(){
  23. return date('Y-m-d');
  24. }
  25. # 3.判断时间大小
  26. # 1大于2则返回1,相等返回0,小于返回-1
  27. public static function ifIsBigDate($date1,$date2){
  28. if(strtotime($date1) > strtotime($date2)){
  29. return 1;
  30. }else if(strtotime($date1) == strtotime($date2)){
  31. return 0;
  32. }else{
  33. return -1;
  34. }
  35. }
  36. public static function getWeekOneDate($date){
  37. $week = date('w',strtotime($date));
  38. //echo $date;
  39. //echo $week;
  40. $c = $week - 1;
  41. return date("Y-m-d",strtotime($date." -$c days " ));
  42. }
  43. # 4.通过date,得到年-周。
  44. public static function getYearAndWeek($date){
  45. //$date = strtotime($date);
  46. $month = date('m',strtotime($date));
  47. $week = date('W',strtotime($date));
  48. $year = date('Y',strtotime($date));
  49. $intMonth = (int)$month;
  50. $intWeek = (int)$week;
  51. if(($intMonth == 1) && $intWeek > 10){
  52. $week = "00";
  53. }
  54. return $year."-".$week;
  55. }
  56. # 得到间隔天数
  57. public static function diffBetweenTwoDays($day1, $day2)
  58. {
  59. $second1 = strtotime($day1);
  60. $second2 = strtotime($day2);
  61. return abs($second1 - $second2) / 86400;
  62. }
  63. }