• We just launched and are currently in beta. Join us as we build and grow the community.

Digital Clock using jQuery

ItsLeoTM

Cyber Evidence Collector
I Rep
0
0
0
Rep
0
I Vouches
0
0
0
Vouches
0
Posts
37
Likes
187
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 400 XP
In this article, we are going to create Digital Clock using jQuery. You can use this simple program to your thesis projects or any kind of systems that you've created. Kindly download the full source code below.

You will Learn:

  • You can learn to construct simple markup using HTML.
  • You can learn to create stylish Digital Clock.
  • You can learn to build Digital Clock using jQuery.

Creating Markup

Creating simple HTML source code to display our Digital Clock. Kindly copy and paste this short source code to your BODY tag of your page.

  1. <a

    href

    =

    ""

    style

    =

    "text-decoration:line-through; color:blue;"

    ><h1

    >

    Digital Clock using jQuery</

    h1

    ></

    a

    >
  2. <div

    class

    =

    "container"

    >
  3. <div

    class

    =

    "clock"

    >
  4. <div

    id

    =

    "Date"

    ></

    div

    >

  5. <ul

    >
  6. <li

    id

    =

    "hours"

    >

    </

    li

    >
  7. <li

    id

    =

    "point"

    >

    :</

    li

    >
  8. <li

    id

    =

    "min"

    >

    </

    li

    >
  9. <li

    id

    =

    "point"

    >

    :</

    li

    >
  10. <li

    id

    =

    "sec"

    >

    </

    li

    >
  11. </

    ul

    >

  12. </

    div

    >
  13. </

    div

    >

Constructing CSS Style

This style where you can edit your Digital Clock design. After downloading the source code below, try to edit the design more attractive to the user. Enjoy coding.

  1. body{
  2. background

    :

    #f5f5f5

    ;
  3. font

    :

    bold

    12px

    Arial,

    Helvetica,

    sans-serif

    ;
  4. margin

    :

    0

    ;
  5. padding

    :

    0

    ;
  6. min-width

    :

    960px

    ;
  7. color

    :

    #000

    ;
  8. }

  9. a {
  10. text-decoration

    :

    none

    ;
  11. color

    :

    darkblue

    ;
  12. }

  13. h1 {
  14. font

    :

    4em

    normal

    Arial,

    Helvetica,

    sans-serif

    ;
  15. padding

    :

    20px

    ;

    margin

    :

    0

    ;
  16. text-align

    :

    center

    ;
  17. }

  18. h1 small

    {
  19. font

    :

    0.2em

    normal

    Arial,

    Helvetica,

    sans-serif

    ;
  20. text-transform

    :

    uppercase

    ;

    letter-spacing

    :

    0.2em

    ;

    line-height

    :

    5em

    ;
  21. display

    :

    block

    ;
  22. }

  23. h2 {
  24. font-weight

    :

    700

    ;
  25. color

    :

    #bbb

    ;
  26. font-size

    :

    20px

    ;
  27. }

  28. h2,

    p {
  29. margin-bottom

    :

    10px

    ;
  30. }

jQuery Script

This script that we are going to construct helps us to display a Digital Clock in our page. We have the list of months and name of the day. Copy and paste this script to your HEAD tag of your page.

  1. <

    script type=

    "text/javascript"

    >
  2. $(

    document)

    .ready

    (

    function

    (

    )

    {
  3. // Create two variable with the names of the months and days in an array
  4. var

    monthNames =

    [

    "January"

    ,

    "February"

    ,

    "March"

    ,

    "April"

    ,

    "May"

    ,

    "June"

    ,

    "July"

    ,

    "August"

    ,

    "September"

    ,

    "October"

    ,

    "November"

    ,

    "December"

    ]

    ;
  5. var

    dayNames=

    [

    "Sunday"

    ,

    "Monday"

    ,

    "Tuesday"

    ,

    "Wednesday"

    ,

    "Thursday"

    ,

    "Friday"

    ,

    "Saturday"

    ]

  6. // Create a newDate() object
  7. var

    newDate =

    new

    Date

    (

    )

    ;
  8. // Extract the current date from Date object
  9. newDate.setDate

    (

    newDate.getDate

    (

    )

    )

    ;
  10. // Output the day, date, month and year
  11. $(

    '#Date'

    )

    .html

    (

    dayNames[

    newDate.getDay

    (

    )

    ]

    +

    " "

    +

    newDate.getDate

    (

    )

    +

    ' '

    +

    monthNames[

    newDate.getMonth

    (

    )

    ]

    +

    ' '

    +

    newDate.getFullYear

    (

    )

    )

    ;

  12. setInterval(

    function

    (

    )

    {
  13. // Create a newDate() object and extract the seconds of the current time on the visitor's
  14. var

    seconds =

    new

    Date

    (

    )

    .getSeconds

    (

    )

    ;
  15. // Add a leading zero to seconds value
  16. $(

    "#sec"

    )

    .html

    (

    (

    seconds <

    10

    ?

    "0"

    :

    ""

    )

    +

    seconds)

    ;
  17. }

    ,

    1000

    )

    ;

  18. setInterval(

    function

    (

    )

    {
  19. // Create a newDate() object and extract the minutes of the current time on the visitor's
  20. var

    minutes =

    new

    Date

    (

    )

    .getMinutes

    (

    )

    ;
  21. // Add a leading zero to the minutes value
  22. $(

    "#min"

    )

    .html

    (

    (

    minutes <

    10

    ?

    "0"

    :

    ""

    )

    +

    minutes)

    ;
  23. }

    ,

    1000

    )

    ;

  24. setInterval(

    function

    (

    )

    {
  25. // Create a newDate() object and extract the hours of the current time on the visitor's
  26. var

    hours =

    new

    Date

    (

    )

    .getHours

    (

    )

    ;
  27. // Add a leading zero to the hours value
  28. $(

    "#hours"

    )

    .html

    (

    (

    hours <

    10

    ?

    "0"

    :

    ""

    )

    +

    hours)

    ;
  29. }

    ,

    1000

    )

    ;

  30. }

    )

    ;
  31. </

    script>

Output

untitled_13.jpg


Kindly click the "Download Code" button below for full source code. Thank you very much.

If you are interested in programming, we have an example of programs that may help you even just in small ways.

Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.


Download
You must upgrade your account or reply in the thread to view hidden text.
 

449,193

322,229

322,238

Top