728x90

padStart()
padStart() 메서드는 현재 문자열의 시작을 다른 문자열로 묶음, 주어진 길이를 만족시키는 새로운 문자열을 반환합니다.
str.padStart(targetLength [, padString])
targetLength
목표 문자열 길이. 현재 문자열의 길이보다 작다면 충전물이 그대로 반환됩니다.
padString현재 문자열에 채워넣기를 다른 문자열입니다.
반환값 : String
const str1 = '5';
console.log(str1.padStart(2, '0'));
// expected output: "05"
'abc'.padStart(10); // " abc"
'abc'.padStart(10, "foo"); // "foofoofabc"
'abc'.padStart(6,"123465"); // "123abc"
'abc'.padStart(8, "0"); // "00000abc"
'abc'.padStart(1); // "abc"
Date.parse()
parse()
날짜 문자열을 구문 분석하고 1970년 1월 1일 이후의 시차를 반환합니다.
parse()
시간차를 밀리초 단위로 반환합니다.
[Example]
1970년 1월 1일부터 2012년 3월 21일까지의 연수를 계산하십시오.
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Dates</h2>
<p>parse() parses a date string and returns the number of milliseconds since midnight January 1, 1970.</p>
<p>Calculate the number of years between March 21, 2012 and January 1, 1970:</p>
<p id="demo"></p>
<script>
// Calculate milliseconds in a year
const minute = 1000 * 60;
const hour = minute * 60;
const day = hour * 24;
const year = day * 365;
// Compute years
const d = Date.parse("March 21, 2012");
let years = Math.round(d / year);
document.getElementById("demo").innerHTML = years;
</script>
</body>
</html>
[결과값 이미지]

정리 출처 :
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/padStart
https://www.w3schools.com/JSREF/jsref_parse.asp
728x90
'STUDY > JavaScript' 카테고리의 다른 글
| [JS] 자바스크립트 내장 객체 (0) | 2023.01.16 |
|---|---|
| [JS] prototype 이란? (0) | 2023.01.16 |
| [JS] arguments 객체 (0) | 2023.01.05 |
| [JS] spread operator - 배열의 복사 (0) | 2023.01.05 |
| [JS] 배열 순회 for · for-in · for-of · forEach (0) | 2023.01.03 |