如何使用PHP

时间:2018-01-31 03:30:06

标签: php date

我使用WP Download Manager Pro在WP网站上工作。我可以像这样访问对象的日期:

<?php $packageID = get_field('user_submitted_app_download_id'); $post_date = $package['post_date'];?>

它将返回这样的日期&#34; 2018-01-03 10:56:11&#34;我需要重新安排它,以便像这样发布&#34; 03-01-2018&#34; - &GT;米-d-Y

我一直在犯错,不知道自己做错了什么。来自PHP.net -

<?php $post_date = $package['post_date']; echo date_format($post_date, m-d-Y); ?>

我收到了这个错误清单:

  

注意:使用未定义的常数m - 假设&#39; m&#39;在   /home/ntecosys/sandboxwp2/wp-content/plugins/facetwp/includes/class-renderer.php(467)   :eval()&#39; d代码在第18行

     

注意:使用未定义的常数d - 假设&#39; d&#39;在   /home/ntecosys/sandboxwp2/wp-content/plugins/facetwp/includes/class-renderer.php(467)   :eval()&#39; d代码在第18行

     

注意:使用未定义的常数Y - 假设&#39; Y&#39;在   /home/ntecosys/sandboxwp2/wp-content/plugins/facetwp/includes/class-renderer.php(467)   :eval()&#39; d代码在第18行

     

警告:date_format()期望参数1为DateTimeInterface,   给出的字符串   /home/ntecosys/sandboxwp2/wp-content/plugins/facetwp/includes/class-renderer.php(467)   :eval()&#39; d代码在第18行

如何重新格式化日期?

2 个答案:

答案 0 :(得分:1)

我相信你必须在报价

中包装你的日期格式
{{1}}

答案 1 :(得分:1)

您的/* JAVA 8 using streams*/ public static void main(String args[]) { Map<Integer, Boolean> map = new HashMap<Integer, Boolean>(); map.put(100, true); map.put(1011, false); map.put(1022, false); Map<Integer, Boolean> map1 = new HashMap<Integer, Boolean>(); map1.put(100, false); map1.put(101, false); map1.put(102, false); boolean b = map.entrySet().stream().filter(value -> map1.entrySet().stream().anyMatch(value1 -> (value1.getKey() == value.getKey() && value1.getValue() == value.getValue()))).findAny().isPresent(); System.out.println(b); } 是一个字符串,而$post_date需要一个DateTime对象。

这是将字符串转换为unix时间戳的较短方法:

date_format()

否则,您需要使用date_create_from_format将字符串解析为可以使用echo date('m-d-Y' strtotime($post_date)); 操作的对象,但这更详细。