Skip to main content

Posts

Showing posts from April 17, 2016

Running Clock

Current Time is : Here is the code <html> <head> <script> function updateClock() { var currentTime = new Date(); var currentHours = currentTime.getHours ( ); var currentMinutes = currentTime.getMinutes ( ); var currentSeconds = currentTime.getSeconds ( ); // Pad the minutes and seconds with leading zeros, if required currentMinutes = ( currentMinutes currentSeconds = ( currentSeconds // Choose either "AM" or "PM" as appropriate var timeOfDay = ( currentHours // Convert the hours component to 12-hour format if needed currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours; // Convert an hours component of "0" to "12" currentHours = ( currentHours == 0 ) ? 12 : currentHours; // Compose the string for display var ...

Real time changing Clock showing date and time

We can display a clock which will be showing the local time of the client computer by using JavaScript. Note that this time displayed is taken from user computer and not from the server.  We have seen in our  date object example how to display current date and time   where the current date and time is displayed once. Here we will try to display changing clock or real time change in date and time by using  setTimeout function . This setTimeout function we have used to trigger the time display function in a refresh rate of 1000 mill seconds ( 1 Sec ). This refresh rate can be changed to any other value. By changing the value to 5000 the clock will refresh and show the exact time once in every 5 seconds.  Here is the demo of this script and code is given below that.  Sat Apr 23 2016 08:27:22 GMT+0530 (IST)   Here is the code <html> <head> <title>(Type a title for your page here)</title> <script type="text/javascript...

Timer funcitons in JavaScript: Reminder Script

Timers are used in web pages and we will discuss how to setup one and how to use one with an example. The function setTimeout() in function is used and here is its general syntax. mytime = setTimeout(expression, msec); mytime  is the identifier used to identify the current timeout function.  expression  is the statement that is to be executed after the specified time has ticked off.  msec  is the duration of time in milliseconds after which the expression will be executed.  You can see by using setTimeout function we can execute any function or object after a set of time. For example if msec is set 5000 then the expression will be executed after 5 seconds or 5000 milliseconds.  We will try one example where we will have four period buttons and each button will set a different time for another function to execute and display a alert button. We will call it as a reminder script and we will get one alert box based on the period button we click...

JavaScript Date functions

Functions Description Date Object Displaying date and time in an alert window getTime() milliseconds that is passed from January 1, 1970 getMonth month part of the date object, showing month number from 0 to 11 getYear Getting the year in YYYY format from the data object getDate Date of the month starting from 1 to 31 and formatting getDay Returns 0 for Sunday and 1 for Monday .. 6 for Saturday getMinutes Minute part of the date object, starting from 0 to 59 getHours Hour part of the date object, starting from 0 to 23 getSeconds Seconds part of the date object, starting from 0 to 59 setDate Changing the date object by changing the date of the month setMonth Setting the month part of the date object by using numbers 0 to 11 setfullyear Setting to full year the date object setHours Changing the hour part of date object, from 0 to 23 or to any other value setMinutes Changing the Minute part of date object, from 0 to 59 or to any other value toString Before using any stri...