Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why is a @ symbol required for some DateTime objects in php

Tags:

php

datetime

When creating a DateTime object with a unix timestamp, why does a '@' symbol need to precede the time stamp?

like image 633
deadman1204 Avatar asked Mar 01 '13 19:03

deadman1204


People also ask

What is the use of date() function in PHP?

The date() function formats a local date and time, and returns the formatted date string.

How do we use DateTime objects in PHP give examples?

A few examples of creating DateTime objects with valid time string: $yesterday = new DateTime('yesterday'); $twoDaysLater = new DateTime('+ 2 days'); $oneWeekEarly = new DateTime('- 1 week'); The second parameter of the DateTime's constructor allows us to specify a timezone.


2 Answers

As far as I know it is so that the timestamp can be identified from other valid formats.

http://www.php.net/manual/en/datetime.formats.php

unix timestamp is under the compound formats.

like image 173
Jonathan Kuhn Avatar answered Oct 12 '22 23:10

Jonathan Kuhn


It's been quite long since the question is asked, but if anyone still looking for the answer and landed on this question. Then here's it is.

Using '@' symbol

echo date("dS M Y \\@\\ g:ia");
// 18th Jun 2020 @ 4:20pm

Using 'at' text

echo date("dS M Y \\a\\t g:ia");
// 18th Jun 2020 at 4:20pm

Using 'and' text

echo date("dS M Y \\a\\n\\d g:ia");
// 18th Jun 2020 and 4:20pm 
like image 32
Dexter Avatar answered Oct 13 '22 01:10

Dexter