获取Twig的开始日期date_modify

我正在尝试开始今天在Twig的日期和时间。我发现您可以通过执行以下操作来开始当前的一周:

{{ now | date_modify('monday this week')|date('d-m-y H:i:s') }}

所以我认为今天开始会有一种方法。到目前为止,我已经尝试过:

{{ now | date_modify('start of day')|date('d-m-y H:i:s') }}

{{ now | date_modify('start of today')|date('d-m-y H:i:s') }}

导致的结果:

  

PHP警告:DateTime :: modify():无法解析位置0处的时间字符串(一天的开始)

     

PHP警告:DateTime :: modify():无法解析位置0处的时间字符串(今天开始)

我想知道:

  1. 问这个的正确语法是什么?
  2. 在哪里可以找到这些字符串的列表?
  3. 传递字符串的任何替代方法

谢谢。

lj0122 回答:获取Twig的开始日期date_modify

您可以在以下位置找到这些字符串:https://www.php.net/manual/en/datetime.formats.relative.php

所以我认为您正在寻找的是: <?php $start = "01-10-2019"; $end = "31-10-2019"; $test = "01-11-1968"; $start = new \DateTime($start); $end = new \DateTime($end); $test = new \DateTime($test); function isBetweenDateIgnoreYear(\DateTime $startInput,\DateTime $endInput,\DateTime $checkInput) { $start = clone $startInput; $end = clone $endInput; $check = clone $checkInput; $currentYear = (int) date('Y'); $start->setDate($currentYear,(int) $start->format('m'),(int) $start->format('d')); $end->setDate($currentYear,(int) $end->format('m'),(int) $end->format('d')); $check->setDate($currentYear,(int) $check->format('m'),(int) $check->format('d')); return ($start <= $check && $check <= $end); } $result = isBetweenDateIgnoreYear($start,$end,$test); var_dump($result);

,
{{ date('today') | format_datetime() }}

date(以及 date_modify)使用 PHP 的 strtotime 函数。 today 指当天的 00:00:00,如 PHP’s relative format reference 中所述。

本文链接:https://www.f2er.com/3150629.html

大家都在问