How to print date and time with jquery

alias51

Simple question: how can I display a browser's current date and time in the format below?:

<h2>[current time, e.g. 02.32am]</h2>
<h4>[day of week, e.g. saturday]</h4>
<h3>[full date, e.g. 11 November 2013]</h3>
vogomatix

Create a Javascript Date object and display the values from that.

var today = new Date();
// What happens next depends on whether you want UTC or locale time...
// assuming locale time in this example...
$('#time').html( today.getHours() + ':' + today.getMinutes());
$('#weekday').html(today.toDateString().substring(0,3));
$('#date').html( today.toDateString() );
<h2 id="time"></h2>
<h4 id="weekday"></h4>
<h3 id="date"></h3>

Alternatively use DatePicker from JQueryUI to generate your date strings e.g.

 $('#date').html( $.datepicker.formatDate( "dd MM YY", today ) );
 $('#weekday').html( $.datepicker.formatDate( "DD", today ));

Remember to load jQueryUI to do this. Datepicker is quite powerful and has many other useful abilities including locale handling

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to print Current Time and Date

From Dev

How to print Current Time and Date

From Dev

How to print the date and time in Python from string?

From Dev

how can you print the time and date in python

From Dev

How to print a concatenated date and time in seconds

From Dev

How to print current Time and Date in Q Basic?

From Dev

How to print the current time and date in ISO date format in java?

From Dev

How to print the date from milliseconds based on Macintosh time

From Dev

how to print date and time in one line in bash script?

From Dev

Format date time in jQuery

From Dev

Jquery date time format

From Dev

How can I print a date/time from time::strftime without leading zeros?

From Dev

How can I print a date/time from time::strftime without leading zeros?

From Dev

Set Date Time to Jquery date time picker

From Dev

Set Date Time to Jquery date time picker

From Dev

How to use regex to validate Date and Time using Match in Jquery

From Dev

How to show current date with time AM PM and CST using jquery

From Dev

How to set end date greater the start date using jquery date time picker

From Dev

How to set end date greater the start date using jquery date time picker

From Dev

bash to print log with user, date, and time

From Dev

Print date and time for the beginning of the current week (in bash)

From Dev

How can I make AngularJS simply print the date without applying a time zone ?

From Dev

How can I print the 'date received' only one time while using a for loop?

From Dev

Problems with set the Date and Time JQuery

From Dev

Jquery Ui date time picker

From Dev

Jquery date time picker issue

From Dev

Date time format jquery template

From Dev

Jquery localize UTC Date Time

From Dev

jquery UI date time picker

Related Related

  1. 1

    How to print Current Time and Date

  2. 2

    How to print Current Time and Date

  3. 3

    How to print the date and time in Python from string?

  4. 4

    how can you print the time and date in python

  5. 5

    How to print a concatenated date and time in seconds

  6. 6

    How to print current Time and Date in Q Basic?

  7. 7

    How to print the current time and date in ISO date format in java?

  8. 8

    How to print the date from milliseconds based on Macintosh time

  9. 9

    how to print date and time in one line in bash script?

  10. 10

    Format date time in jQuery

  11. 11

    Jquery date time format

  12. 12

    How can I print a date/time from time::strftime without leading zeros?

  13. 13

    How can I print a date/time from time::strftime without leading zeros?

  14. 14

    Set Date Time to Jquery date time picker

  15. 15

    Set Date Time to Jquery date time picker

  16. 16

    How to use regex to validate Date and Time using Match in Jquery

  17. 17

    How to show current date with time AM PM and CST using jquery

  18. 18

    How to set end date greater the start date using jquery date time picker

  19. 19

    How to set end date greater the start date using jquery date time picker

  20. 20

    bash to print log with user, date, and time

  21. 21

    Print date and time for the beginning of the current week (in bash)

  22. 22

    How can I make AngularJS simply print the date without applying a time zone ?

  23. 23

    How can I print the 'date received' only one time while using a for loop?

  24. 24

    Problems with set the Date and Time JQuery

  25. 25

    Jquery Ui date time picker

  26. 26

    Jquery date time picker issue

  27. 27

    Date time format jquery template

  28. 28

    Jquery localize UTC Date Time

  29. 29

    jquery UI date time picker

HotTag

Archive