Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Real Time, Date, Day of the Week in javascript or jquery [closed]

How to show real time, date, day in this format?

enter image description here

The time should be actual (which runs the seconds count).

Thanks guys!

like image 500
kgam Avatar asked Feb 24 '15 06:02

kgam


People also ask

How do I get the current day of the week in JavaScript?

Call the getDay() method on the Date object to get the day of the week. The getDay method returns the day of the week for the specific date, represented as an integer between 0 and 6 , where 0 is Sunday and 6 is Saturday.

How can get today day in jquery?

You can do it like that: var d = new Date(); var month = d. getMonth()+1; var day = d. getDate(); var output = d.

How do I display current week in HTML?

HTML input type="week"


1 Answers

To update time panel every second we should use setInterval() function.

To format date the way you need the best approach is to use moment.js library. The code is shortened greatly:

$(document).ready(function() {
    var interval = setInterval(function() {
        var momentNow = moment();
        $('#date-part').html(momentNow.format('YYYY MMMM DD') + ' '
                            + momentNow.format('dddd')
                             .substring(0,3).toUpperCase());
        $('#time-part').html(momentNow.format('A hh:mm:ss'));
    }, 100);
});

Here is working fiddle

like image 171
Ivan Gerasimenko Avatar answered Oct 13 '22 19:10

Ivan Gerasimenko