ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 2022_01_02 기념일 계산기
    IT/js 2022. 1. 3. 04:34
    객체(Oject) 알아보기

    여러개의 값을 담는 자료

    var person = {
    	name: 'Youngjin',  // 속성명(키) : 속성값(값)
        age:20,
        hobby : ['코딩', '축구'],
        sayHello : function(){	// 이것은 메서드
        console.log('hello')
        }
    }

    객체.키 쓰면 나온다

    person.name;
    // Youngjin
    
    person.sayHello();
    // hello

     

    날짜를 다룰때 사용하는 Data 객체

    js내부에 특정 데이터를 담고있는 것이 내장 객체

    var now = new Date();
    now.getMonth();
    now.getData();
    now.getTime();
    
    // 관련 메소드가 담겨있다
    
    var now = new Date();
    	now.getFullYear(); 	// 연도
        now.getMonthh(); 	// 월 +1 해야함
        now.getData(); 		// 일
        now.getTime();		// 1970년 기준으로 부터의 초

     

    기념일 계산기 만들기

     

    var now = new Date();
    var start = new Date('2019-06-07');
    
    var timeDiff = now.getTime() - start.getTime();
    var day = Math.floor(timeDiff / (1000 * 60 * 60 * 24) + 1);
    $('#love').text(day + '일째');
    // ms 라서 1000, 초, 분, 시간 +1
    // Math.floor -> 소수점을 날려줌
    
    $('day').text( day + '일째');
    // cosnole.log(day):
    
    var valentine = new Date('2022-02-14');
    var timeDiff2 = valentine.getTime() - now.getTime();
    var day2 = Math.floor(timeDiff2 / (1000 * 60 * 60 * 24) + 1);
    $('#valentine').text(day2 + '일 남음');
    
    // start, 1000일째 
    var ms = start.getTime() + 999 * (1000 * 60 * 60 * 24); // 1000일 ms
    var thousand = new Date(ms); // 1000일 객체 생성
    var thousandDate = thousand.getFullYear() +'.' + (thousand.getMonth() +1) + '.' + thousand.getDate();
    $('#thousand-date').text(thousandDate);
    
    var thousandday = new Date(thousandDate);
    var timeDiff3 = thousandday.getTime() - now.getTime();
    var day3 = Math.floor(timeDiff3 / (1000 * 60 * 60 * 24) + 1);
    $('#thousand').text(day3 + '일 남음');

     

     

Designed by Tistory.