读书人

XML 值解析,该怎么解决

发布时间: 2012-02-20 21:18:23 作者: rapoo

XML 值解析
我的XML文件来自google Android 短信导出得到的。

<smss date="676876876876">

<address data="1264565569028">
<sms date="5435435435435" read="1" status="-1" type="1" body="fdsfdsfsdfsf"/>
<sms date="65876876876876" read="1" status="-1" type="2" body="54654tgfffhfhfg"/>
</address>

<address data="1264566063050">
<sms date="879868698" read="1" status="-1" type="1" body="8678768979878798gfdg"/>
<sms date="54765787687" read="1" status="-1" type="1" body="76876978098p009o"/>
<sms date="6y5765875" read="1" status="-1" type="1" body="76576587698798"/>
</address>

<address data="1264566757586">
<sms date="676787687" read="1" status="-1" type="1" body="hgfdhdghgdhg"/>
<sms date="5try" read="1" status="-1" type="1" body="gfdhggdhgd"/>
<sms date="y65y65" read="1" status="-1" type="1" body="reetrytr"/>
<sms date="y65y65" read="1" status="-1" type="1" body="ytrytrytrytr"/>
<sms date="y65y65" read="1" status="-1" type="1" body="ytrytrytry"/>
<sms date="y65y65" read="1" status="-1" type="1" body="uyiyjuyiu"/>
<sms date="y65y65" read="1" status="-1" type="1" body="oyoiukiu"/>
<sms date="y65y65" read="1" status="-1" type="1" body="ikyiy"/>
<sms date="y65y65" read="1" status="-1" type="1" body="kyiuykuykuy"/>
<sms date="y65y65" read="1" status="-1" type="1" body="kiykikuui"/>
</address>

</smss>

其中<address data="1264565569028"> 中的data肯定是日期格式。不知道有什么方法能转换成正常显示的日期伐?

[解决办法]
function millisecondsStrToDate(str){
var startyear = 1970;
var startmonth = 1;
var startday = 1;
var d, s;
var sep = ":";
d = new Date();
d.setFullYear(startyear, startmonth, startday);
d.setTime(0);
d.setMilliseconds(str);
s = d.getYear() + "-" + (d.getMonth()+1) + "-" + d.getDate() + " " +
d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
//alert(d.toLocaleString());
return d.toLocaleString();

}

读书人网 >XML SOAP

热点推荐