2026, 새로운 도약을 시작합니다.

년,월,일 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개

채택된 답변
+20 포인트

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

Copy








    

    

    

    Current Time

    

        * {

            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;

        }

    





    

        

        

    

    

        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);

    





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

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

우와 친절한 설명까지 너무너무 감사드립니다.
진정한 웝메이커 맞습니다.

댓글을 작성하려면 로그인이 필요합니다.

참고해 보세요

https://sir.kr/g5_tip/18447

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인
🐛 버그신고