获取服务器时间ajax
Posted 放荡不羁的春天
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取服务器时间ajax相关的知识,希望对你有一定的参考价值。
$.ajax({ type:"OPTIONS", url:"/", complete:function(x){ // alert(x.getResponseHeader("Date")) var time = x.getResponseHeader("Date"); var curDate = new Date(time); var year = curDate.getFullYear(); var month = curDate.getMonth() + 1; var day = curDate.getDate(); var hour = curDate.getHours(); var minu = curDate.getMinutes(); var seconds = curDate.getSeconds(); var millsecond = curDate.getMilliseconds(); //获取服务器毫秒数(0-999) if (month < 10) { month = ‘0‘ + month; } if (day < 10) { day = ‘0‘ + day; } if (hour < 10) { hour = ‘0‘ + hour; } if (minu < 10) { minu = ‘0‘ + minu; } if (millsecond < 10) { millsecond = ‘0‘ + millsecond; } if (seconds < 10) { seconds = ‘0‘ + seconds; } years = ‘‘ + year; years = years.substr(2, 2); // document.getElementById("createDates").value = ‘‘ + year // + ‘-‘ + month + ‘-‘ + day + ‘ ‘ + hour + ‘:‘ + minu // + ‘:‘ + seconds; var aa = ‘‘ + year + ‘-‘ + month + ‘-‘ + day + ‘ ‘ + hour + ‘:‘ + minu + ‘:‘ + seconds; console.log(aa); } })
以上是关于获取服务器时间ajax的主要内容,如果未能解决你的问题,请参考以下文章