튜터의 ChatGPT
<div class="greeting">
<h1>Hello, My name!</h1>
<h1 id="current-time"></h1>
</div>
<script>
// 시간 chatgpt
function displayCurrentTime() {
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
// Add leading zeros to minutes and seconds if they are less than 10
minutes = (minutes < 10 ? "0" : "") + minutes;
seconds = (seconds < 10 ? "0" : "") + seconds;
// Determine if it's AM or PM
var meridiem = hours >= 12 ? "PM" : "AM";
// Convert to 12-hour format
hours = hours % 12;
hours = hours ? hours : 12;
// Display the time in HH:MM:SS format
var timeString = hours + ":" + minutes + ":" + seconds + " " + meridiem;
// Display the time in an element with id "current-time"
document.getElementById("current-time").innerHTML = timeString;
}
// Call the displayCurrentTime function every second to update the time
setInterval(displayCurrentTime, 1000);
</script>
'Javascript' 카테고리의 다른 글
SQLAlchemy로 Database 조작하기 (0) | 2023.12.04 |
---|---|
[fetch] 서버 - 데이터 받기(서울시 미세먼지 데이터) (2) | 2023.12.02 |
JS 코딩테스트_vs-code 연습장 활용해서 풀기 (0) | 2023.11.23 |
프로그래머스 코딩테스트 - Github연동 2배 활용방법 (1) | 2023.11.22 |
One thing's Time_99, 버리고 선택하고 집중하는 시간 (0) | 2023.11.21 |