开发者

Converting string to timestamp?

开发者 https://www.devze.com 2023-01-08 02:03 出处:网络
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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消