function GetServerTime (param, formula) {
/* All HTTP date/time stamps MUST be represented in Greenwich Mean Time (GMT), without exception
*
* This function returns a Date or String type value
*
* var time = GetServerTime(); // [date] Wed Oct 11 2017 09:48:52 GMT+0900 (대한민국 표준시)
var time = GetServerTime(""); // "2017-10-11" , can be any string or variable except as provided below
var time = GetServerTime("day", -1); // "2017-10-10"
var time = GetServerTime("week", -1); // "2017-10-04"
var time = GetServerTime("month", 1); // "2017-11-11"
var time = GetServerTime("year", 1); // "2018-11-11"
*/
var xmlHttp;
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest(); // upper IE7, Chrome, Firefox
xmlHttp.open('HEAD',window.location.href.toString(),false);
xmlHttp.setRequestHeader("Content-Type", "text/html");
xmlHttp.send('');
//return xmlHttp.getResponseHeader("Date");
}else if (window.ActiveXObject) {
//Old versions of IE supported the ability to use ActiveX controls inside the browser.
xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
xmlHttp.open('HEAD',window.location.href.toString(),false);
xmlHttp.setRequestHeader("Content-Type", "text/html");
xmlHttp.send('');
//return xmlHttp.getResponseHeader("Date");
}
//return xmlHttp.getResponseHeader("Date");
var serverTime = xmlHttp.getResponseHeader("Date");
if(param!=null){
var ymd = new Date(serverTime);
param = param.toLowerCase().trim();
if(formula !=null){
if(!typeof formula=="number") {
console.log("변수 formula는 number타입이어야 합니다.");
}
else if(param=="day"){
ymd.setDate(ymd.getDate()+formula);
}
else if(param=="week"){
ymd.setDate(ymd.getDate()+(7*formula));
}
else if(param=="month"){
ymd.setMonth(ymd.getMonth()+formula);
}
else if(param=="year"){
ymd.setFullYear(ymd.getFullYear()+formula);
}
}
var month = '' + (ymd.getMonth() + 1),
day = '' + ymd.getDate(),
year = ymd.getFullYear();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
return [year, month, day].join('-');
}
else{
return new Date(serverTime);
}
}
'dev' 카테고리의 다른 글
아마존 DB 오라클 로컬로 옮겨오기 (0) | 2017.08.17 |
---|---|
myBatis : INSERT 후 시퀀스값 가져오기 (oracle) (0) | 2017.08.07 |
아이엠포트를 사용한 결제 구현하기 (2) | 2017.08.05 |
highlight.js 를 블로그에 옮기기 (0) | 2017.06.18 |