How do I get timestamp from e.g. 22-09-2008
?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Please be careful about time/zone if you set it to save dates in database, as I got an issue when I compared dates from mysql that converted to
timestamp
usingstrtotime
. you must use exactly same time/zone before converting date to timestamp otherwise, strtotime() will use default server timezone.Please see this example: https://3v4l.org/BRlmV
Use PHP function date()
date — Format a local time/date
Here is how I'd do it:
This way, you let the function know what date format you are using and even specify the timezone.
If you have PHP 5.3 or above,
this method works on both Windows and Unix and is time-zone aware, which is probably what you want if you are serious about working with dates.
If you don't care about timezone, or want to use the time zone your server uses:
1222093324 (This will differ depending on your server time zone...)
If you want to specify in which time zone, here EST. (Same as New York.)
1222093305
Or if you want to use UTC. (Same as "GMT".)
1222093289
If you know the format use
strptime
becausestrtotime
does a guess for the format, which might not always be correct. Sincestrptime
is not implemented in Windows there is a custom functionRemember that the returnvalue
tm_year
is from 1900! andtm_month
is 0-11Example:
Given that the function
strptime()
does not work for Windows andstrtotime()
can return unexpected results, I recommend usingdate_parse_from_format()
: