Why does timestamp unix need the '@' prefix for strtotime () to figure this out?

I noticed that it strtotime()handles unix timestamps in an odd way, and I was curious if anyone knows why this is:

var_export(strtotime('1330725042'));  // false
var_export(strtotime('@1330725042')); // 1330725042

Why does it strtotime()return falsewhen specifying a unix timestamp (if the specified timestamp is not a prefix @)?

This is from the internal methods of the library method that I created, which is designed to “resolve” an unknown format variable into a timestamp. Using bare is strtotime()not useful in this case, because it returns an incorrect result when the input value is actually a timestamp.

I reworked the library method to explicitly check the timestamp-like value and return it unchanged, so ... we will not say that there is no more practical use for this issue; I'm just curious.

+5
source share
8 answers

The string that receives strtotime()must be in a specific format. http://www.php.net/manual/en/datetime.formats.php

If it strtotime()does not recognize the input format, it returns FALSE. Since unix time is just a sequence of numbers, it cannot parse them correctly unless you explicitly specify which format you are using. The statement @at the beginning gives the function instructions that this sequence is in unix time format.

. : http://php.net/manual/en/function.strtotime.php

+5

, strtotime UNIX, .

+2

strtotime , "1330725042" - , unix, .

strtotime() , "2 2012 ".

1330725042 unix, strtotime()?

+1

strtotime() , , .

+1

strtotime unix, (, "+1 " "1 " )

@ , , " " php ( ), , unparsable var.

0

, timestamp. , @, , , - PHP @.

, strtotime ?

0
0

, @ timestamp unix, . . http://php.net/manual/en/datetime.formats.compound.php

strtotime('@1 a') -3599, .

0

All Articles