【问题标题】:Try To Know this date is today / tommorrow/ SomeDay ago试着知道这个日期是今天/明天/某天前
【发布时间】:2021-01-01 14:16:55
【问题描述】:

我想检查一个日期是今天、明天、昨天还是以前。 但是我的代码不起作用。

代码:


    public function istimedate($timestamp=''){
          $timestamp=date_create($timestamp);
          $date = strtotime(date($timestamp,"Y-m-d"));
          $current_Time = strtotime(date("Y-m-d"));
    
          if($date == $current_Time) { 
              $day_time = 'Today';
          } elseif(strtotime("-1 day", $date) == $current_Time) {
              $day_time = 'Yesterday';
          } elseif(strtotime("+1 day", $date) == $current_Time) {
              $day_time = 'Tomorrow';
          } else {
              $day_time = 'Someday ago';
          }
          return $day_time; 
        }
    $day = $this->istimedate('2021-01-01 09:33:04');

【问题讨论】:

  • 欢迎来到 Stack Overflow。您应该告诉我们您的代码到底有什么问题。它不编译吗?是否计算错误的值?要改进您的问题,请阅读tourHow do I ask a good question?

标签: time simpledateformat magento-2.0


【解决方案1】:

使用.$date = strtotime(date_format($timestamp,"Y-m-d")); insted of $date = strtotime(date($timestamp,"Y-m-d")); 以正确格式转换的日期

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-08
    • 1970-01-01
    • 2014-10-26
    • 2021-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多