Skip to content

Instantly share code, notes, and snippets.

@AminBusiness
Last active June 13, 2018 18:12
Show Gist options
  • Save AminBusiness/1f0e1041df17392b7b42e1dead5f6f0e to your computer and use it in GitHub Desktop.
Save AminBusiness/1f0e1041df17392b7b42e1dead5f6f0e to your computer and use it in GitHub Desktop.
// source https://jsbin.com
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
//Clock that displays the time of each second
function my_Clock()
{
this.cur_date = new Date();
this.hours = this.cur_date.getHours();
this.minutes = this.cur_date.getMinutes();
this.seconds = this.cur_date.getSeconds();
}
my_Clock.prototype.run = function ()
{
setInterval(this.update.bind(this), 1000);
};
my_Clock.prototype.update = function ()
{
this.updateTime(1);
console.log(this.hours + ":" + this.minutes + ":" + this.seconds);
};
my_Clock.prototype.updateTime = function (secs)
{
this.seconds+= secs;
if (this.seconds >= 60)
{
this.minutes++;
this.seconds= 0;
}
if (this.minutes >= 60)
{
this.hours++;
this.minutes=0;
}
if (this.hours >= 24)
{
this.hours = 0;
}
};
var clock = new my_Clock();
clock.run();
</script>
<script id="jsbin-source-javascript" type="text/javascript">//Clock that displays the time of each second
function my_Clock()
{
this.cur_date = new Date();
this.hours = this.cur_date.getHours();
this.minutes = this.cur_date.getMinutes();
this.seconds = this.cur_date.getSeconds();
}
my_Clock.prototype.run = function ()
{
setInterval(this.update.bind(this), 1000);
};
my_Clock.prototype.update = function ()
{
this.updateTime(1);
console.log(this.hours + ":" + this.minutes + ":" + this.seconds);
};
my_Clock.prototype.updateTime = function (secs)
{
this.seconds+= secs;
if (this.seconds >= 60)
{
this.minutes++;
this.seconds= 0;
}
if (this.minutes >= 60)
{
this.hours++;
this.minutes=0;
}
if (this.hours >= 24)
{
this.hours = 0;
}
};
var clock = new my_Clock();
clock.run();</script></body>
</html>
//Clock that displays the time of each second
function my_Clock()
{
this.cur_date = new Date();
this.hours = this.cur_date.getHours();
this.minutes = this.cur_date.getMinutes();
this.seconds = this.cur_date.getSeconds();
}
my_Clock.prototype.run = function ()
{
setInterval(this.update.bind(this), 1000);
};
my_Clock.prototype.update = function ()
{
this.updateTime(1);
console.log(this.hours + ":" + this.minutes + ":" + this.seconds);
};
my_Clock.prototype.updateTime = function (secs)
{
this.seconds+= secs;
if (this.seconds >= 60)
{
this.minutes++;
this.seconds= 0;
}
if (this.minutes >= 60)
{
this.hours++;
this.minutes=0;
}
if (this.hours >= 24)
{
this.hours = 0;
}
};
var clock = new my_Clock();
clock.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment