按指定格式显示日期时间在开发与时间相关的应用时非常有用,接下来与大家分享下格式化显示日期时间的方法,感兴趣的朋友可以参考下哈
Javascript 是一种由 Netscape 的 LiveScript 发展而来的原型化继承的基于对象的动态类型的区分大小写的客户端脚本语言,主要目的是为了解决服务器端语言,比如 Perl,遗留的速度问题,为客户提供更流畅的浏览效果。
时间为当前时间
- //1.2013-4-9 11:21:32
- //2.2013年4月9日 11点21分32秒
- //3.2013年4月9日 上午11点21分32秒
- //4.2013年4月9日 下午13点21分32秒
- /*
- var thedate = new Date();
- alert(thedate.getFullYear() + '-' + thedate.getMonth() + '-' + thedate.getDate() + ' ' + thedate.toLocaleTimeString());
- alert(thedate.toLocaleDateString() + ' ' + thedate.getHours() + '点' + thedate.getMinutes() + '分' + thedate.getSeconds() + '秒');
- if (thedate.getHours() < 12) {
- alert(thedate.toLocaleDateString() + ' 上午' + thedate.getHours() + '点' + thedate.getMinutes() + '分' + thedate.getSeconds() + '秒');
- }
- else {
- alert(thedate.toLocaleDateString() + ' 下午' + thedate.getHours() + '点' + thedate.getMinutes() + '分' + thedate.getSeconds() + '秒');
- }
- */
来源: