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
Here is a very simple and effective solution using the
split
andmtime
functions:It worked like a charm for me.
With
DateTime
API:The same with the procedural API:
If the above fails because you are using a unsupported format, you can use
Note that if you do not set the
!
, the time portion will be set to current time, which is different from the first four which will use midnight when you omit the time.Yet another alternative is to use the
IntlDateFormatter
API:Unless you are working with localized date strings, the easier choice is likely DateTime.
There is also
strptime()
which expects exactly one format:If you want, put it in a MySQL input type timestamp. The above works very well (only in PHP 5 or later):