이제 오늘 날짜를 나타내도록 구현해봅시다. 자바스크립트에서 현재 시간을 가져올 때는 Date 객체를 사용합니다.

    const today = new Date();

    Note ≡ 자바스크립트의 Date


    자바스크립트의 Date에 대해 더 자세히 알고 싶다면 다음 링크에서 확인할 수 있습니다. Date의 기본 사용법 및 내장된 메서드를 확인할 수 있습니다.

    App 컴포넌트에서 다음과 같이 today 값을 선언하고 console.log를 사용해 출력해봅시다.

    App.js

    import React from 'react';
    import {SafeAreaView, StyleSheet} from 'react-native';
    import DateHead from './components/DateHead';
    
    function App() {
    const today = new Date();
    console.log(today);
    
      return (
        <SafeAreaView>
          <DateHead />
        </SafeAreaView>
      );
    }
    
    const styles = StyleSheet.create({});
    
    export default App;
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.