Skip to main content

Create a Real Time Digital Clock using Javascript

    In this tutorial, we'll be creating a real-time clock using JavaScript. We'll be using the Date object to access the current time and updating the clock display on the screen using JavaScript's built-in methods. This clock can be easily integrated into any web page, and can be customized to match the design of your website. Whether you're a beginner or an experienced developer, this tutorial will show you how to create a functional and visually appealing real-time clock using JavaScript.

index.html

	<html>
      <head>
          <title>Realtime Clock</title>
          <script src="js/script.js"></script>
          <link rel="stylesheet" href="css/style.css">
          <link href="https://fonts.googleapis.com/css?family=Oswald|Roboto:100" rel="stylesheet">
      </head>
      <body onload="realtimeClock()">
          <div class="main-container">
              <h1>REAL TIME CLOCK</h1>
              <div id="clock"></div>
              <img class="img-background" src="image/image.jpg">
          </div>
      </body>
  </html>

style.css

	html, body{
      margin: 0;
      width: 100%;
  }

  .main-container{
      width: 100%;
      height: 1080px;
      position: relative;
  }

  .img-background{
      width: 100%;
      height: auto;
  }

  h1{
      width: 100%;
      margin-top: 15%;
      position: absolute;
      font-size: 8vw;
      font-weight: bold;
      text-align: center;
      color: white;
      font-family: 'Oswald', sans-serif;
      letter-spacing: 5px;
  }

  #clock{
      width: 100%;
      position: absolute;
      font-size: 9vw;
      color: white;
      text-align: center;
      font-family: 'Roboto', sans-serif;
      margin-top: 25%;
  }

script.js

  function realtimeClock() {
    
      var rtClock = new Date();

      var hours = rtClock.getHours();
      var minutes = rtClock.getMinutes();
      var seconds = rtClock.getSeconds();

      var amPm = ( hours < 12 ) ? "AM" : "PM";

      hours = (hours > 12) ? hours - 12 : hours;

      hours = ("0" + hours).slice(-2);
      minutes = ("0" + minutes).slice(-2);
      seconds = ("0" + seconds).slice(-2);

      document.getElementById('clock').innerHTML = 
          hours + "  :  " + minutes + "  :  " + seconds + " " + amPm;
      var t = setTimeout(realtimeClock, 500);

  }
  

Watch Full Video Here

Comments

Popular posts from this blog

Auto Image Slider using CSS Only

     Are you ready to learn how to create an image slider using only CSS? Look no further! In this tutorial, we'll walk you through the step-by-step process of building a sleek and modern image slider using HTML and CSS. No JavaScript required! In this tutorial We'll cover setting up the HTML structure for the slider.       This will include creating the container element and styling the slider with CSS. You'll also learn how to add transitions and animations to create a smooth sliding effect. By the end of this tutorial, you'll have a fully functional image slider that you can use on your own website. Whether you're a beginner or an experienced developer, this tutorial has something for you. So let's get started creating your own image slider using CSS today! index.html <html> <head> <meta charset="utf-8"> <link rel="stylesheet" href="css/style.css"&

Banner image/Hero Image Tutorial with HTML and CSS

     In this video, we will be creating a banner/hero image using CSS. A banner or hero image is a large, full-width image that is typically placed at the top of a website or webpage and is used to visually represent the content or purpose of the page. We will be using CSS properties such as background-image and background-size to create the banner/hero image, as well as some basic layout techniques to ensure that it looks great on all devices. By the end of this tutorial, you will have a fully functional banner/hero image that you can use on your own website. So, if you want to learn how to create a banner/hero image using CSS, be sure to follow this tutorial till the end.   index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Tutorial 6</title> <link rel="stylesheet" href="css/tutorial6.css"> <link href="https://fonts.googleapis.co

Image with Accordion Effect on Hover using CSS and HTML

     Hey there, folks! Are you looking to jazz up your website's image galleries? Well, you've come to the right place! In this tutorial, we'll show you how to create an image with accordion effect on hover using HTML and CSS. First off, let's chat about HTML and CSS. HTML is like the building blocks of web pages, while CSS adds style and personality to your website.       By combining these two, you can create some seriously cool designs that'll knock your user's socks off!In this tutorial, we're gonna be using CSS animation effects to make an accordion effect on an image when a user hovers over it. It's a slick way to add a bit of movement and interactivity to your web design. To get started, we'll walk you through creating a basic HTML structure for your image.       Then, we'll apply some CSS styles to give it that fancy accordion look. Finally, we'll create a hover effect using CSS animation that'll make your image expand and colla