1. JS:
// 获取某个时间格式的时间戳
var stringTime = "2014-07-10 10:21:12";
var timestamp2 = Date.parse(new Date(stringTime));
timestamp2 = timestamp2 / 1000;
//2014-07-10 10:21:12的时间戳为:1404958872
console.log(stringTime + "的时间戳为:" + timestamp2);
<blockquote>来源:http://blog.csdn.net/inuyasha1121/article/details/45093797</blockquote>
上边的方法在iOS device上会有bug,解决办法如下:
var arr = "2016/11/11 11:11:11".split(/[- : \/]/),
date = new Date(arr[0], arr[1]-1, arr[2], arr[3], arr[4], arr[5]);
document.write(date);
2. PHP:
$yearb=((int)substr($data['borrow_time'],0,4));//取得年份
$monthb=((int)substr($data['borrow_time'],5,2));//取得月份
$dayb=((int)substr($data['borrow_time'],8,2));//取得几号
$hourb=((int)substr($data['borrow_time'],-4,1));//取得几号
$minb=((int)substr($data['borrow_time'],-2,2));//取得几号
$borrow_time = mktime($hourb,$minb,0,$monthb,$dayb,$yearb);