js获取系统时间并格式化
2017-06-08 22:13
477 查看
获取系统时间,并格式化
显示效果
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>js显示当前时间</title> </head> <body> <div style="width: 200px;height:200px;" onclick="getNowFormatDate();"> 显示当前时间 </div> <script type="text/javascript"> //获取当前系统时间 function getNowFormatDate() { var date = new Date(); var strMonth = date.getMonth() + 1; var strDate = date.getDate(); var strHour = date.getHours(); var strMin = date.getMinutes(); var strSec = date.getSeconds(); if (strMonth >= 1 && strMonth <= 9) { strMonth = "0" + strMonth; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } if (strHour >= 0 && strHour <= 9) { strHour = "0" + strHour; } if (strMin >= 0 && strMin <= 9) { strMin = "0" + strMin; } if (strSec >= 0 && strSec <= 9) { strSec = "0" + strSec; } var currentdate = date.getFullYear() + '-' + strMonth + '-' + strDate + ' ' + strHour + ':' + strMin + ':' + strSec; alert(currentdate); } </script> </body> </html>
显示效果
相关文章推荐
- JS获取系统当前时间并格式化输出小函数
- JS获取(格式化)系统当前时间
- js获取系统当前时间
- JS之Date对象和获取系统当前时间(转)
- js获取系统当前时间
- js获取系统时间
- js 时间格式化 获取当前时间
- C\C++时间处理函数[获取系统时间,求时间差,格式化输出等]
- js获取系统时间的几种方法
- js 获取当前时间并格式化
- js获取系统当前时间
- Js获取当前日期时间及格式化操作
- JS之Date对象和获取系统当前时间
- c++/c获取系统时间,并格式化输出
- js获取当前系统时间
- java中获取当前系统时间,日期并格式化输出
- js获取系统时间
- Oracle获取系统时间及格式化
- 小例子--获取格式化的系统时间
- js 获取系统时间