在phoneGap中有两个APIs,一个是Geo-location,另一个是Accelerometer,它们都在Accelerometer中返回onSuccess方法中的time-stamp,time-stamp看起来像这个1386115200,但是在Geo-location中它给出了类似于Wed Dec 04 2013 01:41:03 ..的内容
我使用的是geolocation api,当用户开始跟踪时,直到用户停止跟踪,我每隔30秒就得到geolocation api并推入object,在停止跟踪之后,我将这个对象放入JSON.stringify函数中,所以timestamp变成了这个2013-12-04T19:32:43.895Z,所以我如何像1386115200一样转换这个格式,因为我需要这个格式来进一步处理步骤
发布于 2013-12-03 21:22:57
您可以用时间字符串实例化一个新的Date对象,然后将.getTime()除以1000。
小提琴
function convertTimestamp(sTime) {
return Math.round(new Date(sTime).getTime()/1000);
}https://stackoverflow.com/questions/20361407
复制相似问题