Today's date format - Day (Shorthand) Date Num

2019-07-26 23:11发布

问题:

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