JavaScript(29)
-
Javascript 현재 시간을 15단위로 표시하기
function getCurrentTimeRoundedTo15Minutes() { const now = new Date(); // Get the current hour and minute const hours = now.getHours(); const minutes = now.getMinutes(); // Round minutes to the nearest 15-minute increment const roundedMinutes = Math.round(minutes / 15) * 15; // Handle overflow of minutes (e.g., 60 minutes = next hour) const adjustedHours = (roundedMinutes ..
2024.12.05 -
Javascript 모든 항목 replace 하기
let str = 'HH24:MI:SS HH24';str = str.replace(new RegExp('HH24', 'g'), '15');console.log(str); // Output: '15:MI:SS 15'
2024.12.05 -
Javascript 데이터 정렬하기
ascconst replacements = { 'YYYY': '2024', 'HH24': '15', 'HH': '03', 'MI': '12', 'SS': '45' };const keys = Object.keys(replacements).sort((a, b) => a.length - b.length);descconst keys = Object.keys(replacements).sort((a, b) => b.length - a.length);
2024.12.05 -
Javascript 날짜에 패턴 적용하기
function formatCustomDate(date, pattern) { // Replace year, month, day, hours, minutes, seconds dynamically const replacements = { 'YYYY': date.getFullYear().toString(), 'MM': (date.getMonth() + 1).toString().padStart(2, '0'), 'DD': date.getDate().toString().padStart(2, '0'), 'HH24': date.getHours().toString().padStart(2, '0'), // 24-hour format 'HH': (da..
2024.12.05 -
Javascript 문자에서 접두사 검색
var str = "extTreePanel";if (str.startsWith('ext')) { console.log("The string starts with 'ext'.");} else { console.log("The string does not start with 'ext'.");}
2024.12.05 -
Javascript json 데이터 예쁘게 출력하기
원본 데이터[ { id: 1, name: 'John Doe', email: 'john.doe@example.com', age: 31 }, { id: 2, name: 'Jane Smith', email: 'jane.smith@example.com', age: 26 }]적용JSON.stringify(value, replacer, space)alert(`Saved ${changes.length} records:\n${JSON.stringify(changes, null, 4)}`);결과[ { "id": 1, "name": "John Doe", "email": "john.doe@example.com", "age": 31 }, { ..
2024.12.01