//현재 시간 function getTimeStamp(date) { var s = leadingZeros(date.getFullYear(), 4) + '-' + leadingZeros(date.getMonth() + 1, 2) + '-' + leadingZeros(date.getDate(), 2) + ' ' + leadingZeros(date.getHours(), 2) + ':' + leadingZeros(date.getMinutes(), 2) + ':' + leadingZeros(date.getSeconds(), 2); return s; } function leadingZeros(n, digits) { var zero = ''; n = n.toString(); if (n.length < digits) { for (i = 0; i < digits - n.length; i++) zero += '0'; } return zero + n; } //날짜,시간 각각 출력 function setDateTimeVal(date){ let result = new Array(); result.year = date.getFullYear(); // 년도 result.month = date.getMonth() + 1; // 월 result.date = date.getDate(); // 날짜 result.day = date.getDay(); // 요일 result.hour = date.getHours(); // 시 result.minute = date.getMinutes(); // 분 result.second = date.getSeconds(); // 초 result.millisecond = date.getMilliseconds(); // 밀리초 return result; } //문자열 형식의 날짜 각각 출력 function dataStringSplit(date){ var dateArray = date.split('-'); let result = new Array(); result.year = dateArray[0]; result.month = dateArray[1]; result.date = dateArray[2]; return result; } //시간 두자리 체크 function reTimeSet(hour,minute){ hour = (hour > 9)? hour : '0' + hour; minute = (minute > 9)? minute : '0' + minute; var result = new Array(); result.hour = hour; result.minute = minute; return result; } // 기간.이용시간 function reTimeReriod(defaultTime,calTime){ var dateArr = defaultTime.split("-"); // DATE 크로스 브라우징 defaultTime = new Date(dateArr[0] + "/" + dateArr[1] + "/" + dateArr[2]); dateArr = calTime.split("-"); // DATE 크로스 브라우징 calTime = new Date(dateArr[0] + "/" + dateArr[1] + "/" + dateArr[2]); var calVal = calTime - defaultTime; var day = Math.floor(calVal / (1000*60*60*24)); var hour = Math.floor((calVal % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minute = Math.floor((calVal % (1000 * 60 * 60)) / (1000 * 60)); var second = Math.floor((calVal % (1000 * 60)) / 1000); var data = new Array(); data.day = day; data.hour = hour; data.minute = minute; data.second = second; return data; } //분을 시간,분 으로 변환 function changeMinuteAtTime(val){ var result = new Array(); result.hour = parseInt(val / 60); result.minute = parseInt(val % 60); return result; } //시간,분을 분으로 변환 function changeTimeAtMinute(hour,minute){ var result = (hour * 60) + minute; return result; } //시간 표기 변환 function getTimeDiffString(dateString) { const now = new Date(); const date = new Date(dateString); const diffInMs = now - date; const diffInMins = Math.round(diffInMs / (1000 * 60)); if (diffInMins < 1) { return "방금 전"; } else if (diffInMins < 60) { return `${diffInMins}분 전`; } else if (diffInMins < 1440) { const hours = Math.floor(diffInMins / 60); const minutes = diffInMins % 60; return `${hours}시간 ${minutes}분 전`; } else { const days = Math.floor(diffInMins / 1440); return `${days}일 전`; } }