년,월,일 html

년,월,일 html

QA

년,월,일 html

본문

아래는 시계소스 입니다.

그런데 시계만 나오니 2023년10월5일(목)

이렇게 년,월,일(요일)

        PM 7:15:25

이렇게 수정 하고 싶습니다.

고수님들 부탁 드려요.

 

<!DOCTYPE html>

<html>

    <head>

        <meta charset="UTF-8">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <meta http-equiv="X-UA-Compatible" content="ie=edge">

        <title>Current Time</title>

        <style>

            * {

                margin: 0;

                padding: 0;

                box-sizing: border-box;

            }

            .container {

                width: 100%;

                height: 100vh;

                display: flex;

                align-items: center;

                justify-content: center;

                position: relative;

                overflow: hidden;

            }

            .container img {

                width: 100%;

                object-fit: cover;

            }

            #current-time {

                position: absolute;

                color: white;

                font-size: 12rem;

            }

        </style>

    </head>

    <body>

 

        <div class="container">

            <img class="slide1" src="c:\\display/clock/hour_paper.jpg">

            <h1 id="current-time"></h1>

        </div>

 

        <script>

            const time = document.getElementById('current-time'); // id가 'current-time'인 요소

 

            // 1초마다 현재 시각 업데이트

            setInterval(() => {

                const date = new Date(); // 새로운 Date 객체 생성

                time.innerHTML = date.toLocaleTimeString();

            }, 1000);

        </script>

 

    </body>

</html>

이 질문에 댓글 쓰기 :

답변 2

다음과 같은 방법으로 해볼 수 있을 것 같습니다.

 


<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Current Time</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        .container {
            width: 100%;
            height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
            overflow: hidden;
        }
        .container img {
            width: 100%;
            object-fit: cover;
        }
        #current-time {
            position: absolute;
            color: white;
            font-size: 3rem; /* 조절 가능한 글꼴 크기 */
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="container">
        <img class="slide1" src="c:\\display/clock/hour_paper.jpg">
        <h1 id="current-time"></h1>
    </div>
    <script>
        const time = document.getElementById('current-time'); // id가 'current-time'인 요소
        // 1초마다 현재 시각 업데이트
        setInterval(() => {
            const date = new Date(); // 새로운 Date 객체 생성
            const options = {
                year: 'numeric',
                month: 'long',
                day: 'numeric',
                weekday: 'long',
                hour: 'numeric',
                minute: 'numeric',
                second: 'numeric',
                hour12: true, // AM/PM 표시
            };
            const formattedTime = date.toLocaleString(undefined, options);
            time.innerHTML = formattedTime;
        }, 1000);
    </script>
</body>
</html>

 

toLocaleString() 메서드를 사용하여 년, 월, 일, 요일, 시, 분, 초, AM/PM을 포함한 현재 시각을 형식화합니다. 설정된 options 객체를 통해 날짜 및 시간 형식을 지정할 수 있으며, hour12: true를 설정하여 AM/PM 표시를 활성화하여 시계에 원하는 형식의 날짜 및 시간을 표시하게 됩니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 86
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT