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>
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.
Comments