Javascript Current Date and Time

Current Date and Time using Javascript




This Code will output the Current Date (MM/DD/YYYY) and Time (12 hour method) using Javascript 




Javascript


<!DOCTYPE html>
<title>Date and Time</title>

<time id="date"></time>
<time id="time"></time>
<script>
  
var curDate = new Date(),
    month = curDate.getMonth() + 1,
    day = curDate.getDate(),
    year = curDate.getFullYear(),
    date = month + "/" + day + "/" + year;
      
document.getElementById("date").innerHTML = date;
  
  
var curTime = new Date(),
    hours = curTime.getHours(),
    minutes = curTime.getMinutes();
  
if (minutes < 10) {
    minutes  = "0" + minutes;}

var suffix = "AM";
if (hours >= 12) {
    suffix = "PM";
    hours = hours - 12;}
if (hours == 0) {
    hours = 12;}


time = hours + ":" + minutes + " " + suffix;
      
document.getElementById("time").innerHTML = time;
     
</script>


Click here to Run this Code


Share with Friends


Twitter Facebook Google LinkedIn Email Pinterest Reddit StumbleUpon Tumblr



Try these Fun Games by Bobbie:


Travel Blast Game New York


Play and Learn Russian


Battlestarship Game



Take a look at these Groovy Codes:


Fun IQ Test


Html Svg Starburst


Javascript Particles Fishes



Read the Latest Breaking Programming and Tech News, Great Articles and Tips:


Codenewz Programming and Tech News














Comments

Popular posts from this blog

Multi-tap Keypad Text Entry

Crypto Mining