14. 내장 객체 (Built-in Object)
1) 객체 생성
변수명 = new 생성함수();
2) Date 객체
: 날짜나 시간 관련 정보 필요할 때 사용
#1. 객체 생성
변수 = new Date();
변수 = new Date("연/월/일"); 문자열
변수 = new Date(연, 월-1, 일, (시간, 분, 초, 밀리초 등 더 쓸 수 있다));
#2. 메서드
- 정보 가져오기
getFullYear() : 연도 정보
getMonth() : 월 정보 ( 0월~11월)
getDate() : 일 정보
getDay() : 요일 (일:0~ 토:6)
getHour() : 시간정보
getMinutes() : 분
getSeconds() : 초
getMilliseconds() : 밀리초
getTime() : 1970.1.0.0.0부터 경과된 시간을 밀리초로 리턴
- 정보 수집
setFullYear() : 연도 수정
setMonth() : 월 수정 ( 0월~11월)
setDate() : 일 수정
- : 요일은 날짜 바꾸면 자동으로 바뀜 (일:0~ 토:6)
setHour() : 시간정보 수정
setMinutes() : 분 수정
setSeconds() : 초 수정
setMilliseconds() : 밀리초 수정
setTime() : 1970.1.0.0.0부터 경과된 시간을 밀리초로 수정
3) Math 객체
수학 관련 기능과 속성을 제공하는 객체
Math.상수
Math.메서드()
4) Array 객체 : https://itcreator.tistory.com/36
5) String 객체
: 문자형 데이터를 취급하는 객체
변수 = "문자열"; 변수 = '문자열';
변수 = new String("문자열");
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script> // 14-2 ~ 3설명
let today = new Date();
console.log(today);
//let christmas = new Date("2022-12-25"); 값 동일
let christmas = new Date("2022/12/25");
console.log(christmas);
let offday = new Date(2022, 6, 6); //7월 6일
console.log(offday);
// 메서드
let month = today.getMonth(); // -1 해서 줌
console.log(month+1);
let day = today.getDay();
console.log(day);
let date = today.getDate();
console.log(date);
let time = today.getTime();
console.log(time);
console.log(christmas);
christmas.setFullYear(2023); // 년도 수정
console.log(christmas);
christmas.setDate(24); // 날짜 수정
console.log(christmas);
//14-3 Math
// let rd = parseInt(Math.random()*10); / 0~9 사이값
// console.log(rd*100);
// 14-5 String
let str = "hello javascript"
console.log(str.charAt(0)); // h 가져옴
console.log(str.indexOf('j')); //6 (띄워쓰기도 문자)
console.log(str.match("hello")); // 같은 문자열이 있나?
console.log(str.substr(3, 5)); // lo ja (시작인덱스, 글자수)
console.log(str.substring(3, 5)); // lo (시작인덱스, 끝인덱스):끝인덱스 전까지
console.log(str.replace("hello","awesome")); //awesome javascript
console.log(str.split(" ")); //['hello', 'javascript']
</script>
</body>
</html>