Today's date format - Day (Shorthand) Date Number Month (Shorthand) - PHP

折月煮酒 提交于 2019-12-14 02:23:28

问题


I have a feed which gives feed in the following format: "Fri 14 Oct"

I want to see if today's date matches the date from the feed. My problem is the format of today's date/

  $today = date("d m");

This outputs 17 10.

What is the best way to format $today so that it outputs Day (shorthand) space date (number) Month (shorthand) ?


回答1:


how about:

$today = date("D j M");

As explained in date() reference manual.

Anyway you should be aware of timezone issues unless you are 100% sure that your server is in the same timezone of the feed you are comparing.

I would follow a different approach though, you can parse the feed's date using DateTime::createFromFormat() which also understand timezones, and then compare it with today's date.




回答2:


$today = date("D d M");

PHP Date Documentation




回答3:


<?php
// Prints the day
echo date("l") . "<br>";

// Prints the day, date, month, year, time, AM or PM
echo date("l jS \of F Y h:i:s A");
?>

For more details, please visit http://www.w3schools.com/php/func_date_date.asp



来源:https://stackoverflow.com/questions/40076614/todays-date-format-day-shorthand-date-number-month-shorthand-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!