jquery 格式化日期

function setMaxEndDate(){

var beginDate=$("#beginDate").val();
var time = new Date(beginDate.replace("-","/"));
var b = 24*60; //分钟数
time.setMinutes(time.getMinutes() + b, time.getSeconds(), -1);
$("#maxEndDate").val(time.format("yyyy-MM-dd hh:mm:ss"));
/*SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
alert(s.format(date));
alert(s.format(time)); */

}

Date.prototype.format = function(format) {
/*
* 使用例子:format="yyyy-MM-dd hh:mm:ss";
*/
var o = {
"M+" : this.getMonth() + 1, // month
"d+" : this.getDate(), // day
"h+" : this.getHours(), // hour
"m+" : this.getMinutes(), // minute
"s+" : this.getSeconds(), // second
"q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
"S" : this.getMilliseconds()
// millisecond
}

if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4
- RegExp.$1.length));
}

for (var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1
? o[k]
: ("00" + o[k]).substr(("" + o[k]).length));
}
}
return format;
}

时间: 2024-08-03 19:19:28

jquery 格式化日期的相关文章

jquery格式化json格式日期

有时候后台传过来的json里的日期会变成/Date(1498297711000 0800)/这种类型的日期格式,前台可以通过jquery进行日期格式化: function ChangeDateFormat(cellval) { var date = new Date(parseInt(cellval.replace("/Date(", "").replace(")/", ""), 10)); //getMonth()从0开始算

Jquery实现日期格式化

格式一:yyyy-MM-dd HH:mm:ss Date.prototype.format = function(format) { /* * eg:format="yyyy-MM-dd hh:mm:ss"; */ var o = { "M+" : this.getMonth() + 1, // month "d+" : this.getDate(), // day "h+" : this.getHours(), // hou

JavaScript格式化日期

查找格式化日期的方法大都是写日期扩展方法,也许是为了维持jquery easyUI 源码完整性, 1 // 对Date的扩展,将 Date 转化为指定格式的String 2 // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, 3 // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字) 4 // 例子: 5 // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S")

MySQL取得当前时间的函数是什么 格式化日期的函数是什么

取得当前时间用 now() 就行. 在数据库中格式化时间 用DATE_FORMA T(date, format) . 根据格式串format 格式化日期或日期和时间值date,返回结果串. 可用DATE_FORMAT( ) 来格式化DATE 或DATETIME 值,以便得到所希望的格式.根据format字符串格式化date值: %S, %s 两位数字形式的秒( 00,01, . . ., 59) %i 两位数字形式的分( 00,01, . . ., 59) %H 两位数字形式的小时,24 小时(

synchronized/java.util.concurrent.locks.Loc/如何格式化日期/将字符“12345”转换成long型

1.简述synchronized和java.util.concurrent.locks.Lock的异同?解答:主要相同点:Lock能完成synchronized所实现的所有功能 主要不同点:Lock有比synchronized更精确的线程语义和更好的性能.synchronized会自动释放锁,而Lock一定要求程序员手工释放,并且必须在finally从句中释放. 2.如何格式化日期解答:Date now=new Date();SimpleDateFormat sdf=new SimpleDate

iOS开发之格式化日期时间

iOS开发之格式化日期时间 在开发iOS程序时,有时候需要将时间格式调整成自己希望的格式,这个时候我们可以用NSDateFormatter类来处理.例如: //实例化一个NSDateFormatter对象 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; //设定时间格式,这里可以设置成自己需要的格式 [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

实例365(6)---------DateTime.ToString格式化日期,使用DateDiff方法获取日期时间的间隔数

一:DateTime.ToString格式化日期,截图 二:代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace TmrFormat { public part

angular 格式化日期

参考:http://blog.csdn.net/zk437092645/article/details/37882191 html: <input type="text" data-datetimepicker ng-model="phasedate"/> js: //日期控件绑定 app.directive('datetimepicker', function($filter) { var dateFilter = $filter("date

SQLServer格式化日期

SQL Server 格式化日期 CONVERT将某种数据类型的表达式显式转换为另一种数据类型.由于某些需求经常用到取日期格式的不同.现以下可在SQL Server中 将日期格式化.SQL Server 支持使用科威特算法的阿拉伯样式中的数据格式.在表中,左侧的两列表示将 datetime或 smalldatetime 转换为字符数据的style 值.给 style 值加 100,可获得包括世纪数位的四位年份 (yyyy). *    默认值(style 0 或 100.9 或 109.13 或