canvasを用いてJavaScriptで現在時刻を表示する

  • javascript
  • 閲覧343
2
function drawDigitalClock() {
  const canvas = document.getElementById('clockCanvas');
  const context = canvas.getContext('2d');
  const now = new Date();
  const hours = now.getHours();
  const minutes = now.getMinutes();
  const seconds = now.getSeconds();
  
  // C...

///*** 無料ユーザー登録後、正常なすべてのコードが表示されます ***///

					
2023-12-24

canvasを用いてJavaScriptで現在時刻を表示する

コードの説明
canvasを用いて現在時刻をデジタルで表示します

```html
<div>
<canvas id="clockCanvas" width="200" height="50"></canvas>
</div>
```
```css
div { width: 200px; margin: 0 auto; }
canvas { border: 1px solid #000; }
```