xml unix时间戳到mysql时间戳并记录mysql

xml unix时间戳到mysql时间戳并记录mysql,mysql,xml,unix-timestamp,Mysql,Xml,Unix Timestamp,我的XML: } 我的问题: 我的xml源代码有一个unix时间戳,我必须使用mysql时间戳(0000-00-00:00:00) 如何将$time unix timestamp转换为mysql timestamp并记录mysql db?在php中,您可以将时间戳读出为您喜欢的任何格式 date($format,$timestamp) 在MySQL中,您可以使用FROM_UNIXTIME函数将UNIX样式的时间戳(自1970 UTC起的秒数)转换为MySQL时间戳 看这里 <simplet

我的XML:

}

我的问题: 我的xml源代码有一个unix时间戳,我必须使用mysql时间戳(0000-00-00:00:00)
如何将$time unix timestamp转换为mysql timestamp并记录mysql db?

在php中,您可以将时间戳读出为您喜欢的任何格式

date($format,$timestamp)


在MySQL中,您可以使用FROM_UNIXTIME函数将UNIX样式的时间戳(自1970 UTC起的秒数)转换为MySQL时间戳

看这里

<simpletype type="TURKEY">
<city code="01">
    <telcode>(0 322)</telcode>
    <name>Adana</name>
    <time>1345337940</time>
</city>
<city code="02">
    <telcode>(0 416)</telcode>
    <name>Adıyaman</name>
    <time>1340236800</time>
    </city>
</simpletype>
require_once('db.php');
@mysql_connect(_SERVER,_USER,_PASSWORD);
@mysql_select_db(_DATABASE);
$doc = new DOMDocument();
$doc->load( 'CityCode.xml' );
$cities = $doc->getElementsByTagName( "city" );
foreach( $cities as $city )
{
$names = $city->getElementsByTagName( "name" );
$codes = $city->getElementsByTagName( "telcode" );
$times = $city->getElementsByTagName ( "time");
$name = $names->item(0)->nodeValue;
$code = $codes->item(0)->nodeValue;
$time = $times->item(0)->nodeValue;
mysql_query("SET CHARACTER SET utf8"); 
$sql = "INSERT INTO telcode (sehir, name, time) VALUES ('$name' ,'$code'     ,'UNIX_TIMESTAMP ($time') ";
@mysql_query($sql);