ali*_*s51 1 javascript jquery date
简单问题:如何以下面的格式显示浏览器的当前日期和时间?:
<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>
Run Code Online (Sandbox Code Playgroud)
创建一个Javascript Date对象并显示其中的值.
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() );
Run Code Online (Sandbox Code Playgroud)
<h2 id="time"></h2>
<h4 id="weekday"></h4>
<h3 id="date"></h3>
Run Code Online (Sandbox Code Playgroud)
或者使用的DatePicker从jQueryUI的生成您的日期字符串如
$('#date').html( $.datepicker.formatDate( "dd MM YY", today ) );
$('#weekday').html( $.datepicker.formatDate( "DD", today ));
Run Code Online (Sandbox Code Playgroud)
记得加载jQueryUI来做到这一点.Datepicker非常强大,还有许多其他有用的功能,包括语言环境处理
| 归档时间: |
|
| 查看次数: |
15438 次 |
| 最近记录: |