jsp时间获取及格式化
2016-09-09 10:27
316 查看
记录,供自己参考
方法一:原生js使用date函数
方法三:
方法一:原生js使用date函数
//获取系统时间 var now = new Date(); var year = now.getFullYear(); //年 var month = now.getMonth() + 1; //月 var day = now.getDate(); //日 var stop_start_time = year + "-"; //封停开始时间 if(month < 10) stop_start_time += "0"; stop_start_time += month + "-"; if(day < 10) stop_start_time += "0"; stop_start_time += day + " "; //开始时间 $('#stop_start_time').val(stop_start_time);方法二: 与上一种差不多,只是表现形式不一样
function getNowFormatDate() { var date = new Date(); var seperator1 = "-"; var seperator2 = ":"; var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds(); return currentdate; }
方法三:
// 对Date的扩展,将 Date 转化为指定格式的String // 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字) // 例子: // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18 Date.prototype.Format = function (fmt) { //author: meizz var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; } 调用: var time1 = new Date().Format("yyyy-MM-dd"); var time2 = new Date().Format("yyyy-MM-dd HH:mm:ss");
相关文章推荐
- jsp页面获取当前时间并格式化
- jsp采用数据库连接池的方法获取数据库时间戳context.xml配置,jsp页面把时间格式化成自己需要的格式
- java中获取当前系统时间,日期并格式化输出
- java中获取当前系统时间,日期并格式化输出
- jsp日期时间格式化输出
- JS获取系统当前时间并格式化输出小函数
- 获取系统时间,并格式化
- JSP中的几个实用函数(时间判断/IP获取/累计次数/视频播放等)
- C\C++时间处理函数[获取系统时间,求时间差,格式化输出等]
- C语言下获取当前时间并格式化成字符串的方法-可用作截图或者录像的文件名
- 小例子--获取格式化的系统时间
- PHP获取当前日期和时间格式化方法
- oracle 数据库,通过resultSet.getObject()获取时间类型截断的问题的解析(格式化时间不能完全输出,也就是只能到日,小时后面的没有了)
- java中获取当前系统时间,日期并格式化输出
- 在JSP页面获取时间的两种方式
- jsp获取系统时间
- Java,.NET中当前时间获取、格式化方法比较
- 自动同步北京时间,需要启动jboss服务,然后运行127.0.0.1:8080即可,共两个jsp文件,一个获取时间,一个设置时间
- JSP获取服务器当前日期时间的方法
- java 时间 格式化(获取当前时间)