JS 时间与时间戳的相互转换

时间:2024-01-11 11:34:38
<script type="text/javascript">

    var time = "2015-04-22 21:41:43";//2015-4-22 21:41:43
var temp = time.split(' ');
var arr = temp[0].split('-');
var brr = temp[1].split(':');
var timestamp = new Date(Date.UTC(arr[0],arr[1]-1,arr[2],+brr[0]-8,brr[1],brr[2]));
var timestamp = timestamp.getTime()/1000;
alert(timestamp); function getDate(tm){
var tt=new Date(parseInt(tm) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ")
return tt;
}
alert(getDate('1429711045'));
</script>