JS插件(1) 实现 指定格式日期
2014-08-28 00:01
585 查看
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <script> //一个 Date 的扩展方法,用于实现Java的SimpleDateFormat //用法 new Date().formatDate("yyyy年MM月dd日 HH:mm:ss"); //大小写遵循 java 的日期格式 Date.prototype.formatDate=function(format){ var calc=function(num){ if(num<10){ return "0"+num; }else{ return num; } } var _date=format; var day=calc(this.getDate()); var fullDay=this.getDate(); var month=this.getMonth()+1; var fullMonth=calc(this.getMonth()+1); var year=this.getFullYear(); var fullHour =this.getHours(); var hour=fullHour>12? "0"+fullHour-12: fullHour; var minute =this.getMinutes(); var second =this.getSeconds(); _date=_date.replace("yyyy",year) .replace("MM",fullMonth) .replace("M",month) .replace("dd",fullDay) .replace("d",day) .replace("HH",fullHour) .replace("hh",hour) .replace("mm",minute) .replace("ss",second);
return _date; } //使用 alert(new Date().formatDate("yyyy年MM月dd日 hh:MM:ss")); </script> <title>Document</title> </head> </html> </p>
相关文章推荐
- js将long日期格式转换为标准日期格式实现思路
- js实现日历可获得指定日期周数及星期几示例分享(js获取星期几)
- js实现符合国情的日期插件详解
- JS实现span标签显示年月日日期格式
- js 毫秒数转换为指定格式日期的js代码
- js将long日期格式转换为标准日期格式实现思路
- JS对日期按照指定格式进行格式化
- 利用JS实现简单的日期选择插件
- JS、Jquery实现---把后台传过来的时间毫秒数转换成想要的日期格式
- js将毫秒转换成指定格式的日期时间
- JS验证日期的格式YYYY-mm-dd 具体实现
- js实现字符串转日期格式的方法
- js实现字符串转为指定格式的整型或浮点型
- Javascript日期格式化指定格式的字符串实现
- js两行代码按指定格式输出日期时间
- js将long日期格式转换为标准日期格式实现思路
- jQuery日期和时间插件(jquery-ui-timepicker-addon.js)jquerydatapicker插件 实现时分秒
- js实现控制日期输入格式
- js 时间戳转换为指定的日期格式
- js日期操作之根据指定格式获取日期