Converting string to timestamp?
I have a xml file in which date is represented as this: "2010-07-10T14:46:00.000Z" Im parsing it and fetching it as string.
I need to convert it into t开发者_运维百科imestamp or date format to store in db. How do i do it?
Please help.
Assuming that you use PHP:
You can use the function DateTime::createFromFormat(string $format, string $time)
try the following:
$timestamp = str_ireplace(array('T', 'Z'), '', "2010-07-10T14:46:00.000Z");
$datetime = DateTime::createFromFormat('j-m-d H:i:s.u ', $timestamp);
echo $date->getTimestamp();
Please see the documentation of DateTime::createFromFormat and date() for the correct format string.
generally you need to use strptime() related functions, that come from standard C library.
精彩评论