博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
formatDate
阅读量:5304 次
发布时间:2019-06-14

本文共 15804 字,大约阅读时间需要 52 分钟。

//先扩展一下javascript的Date类型,增加一个函数,用于返回我们想要的 yyyy-MM-dd HH:mm:ss 这种时间格式Date.prototype.format = function (pattern) {    /*初始化返回值字符串*/    var returnValue = pattern;    /*正则式pattern类型对象定义*/    var format = {        "y+": this.getFullYear(),        "M+": this.getMonth() + 1,        "d+": this.getDate(),        "H+": this.getHours(),        "m+": this.getMinutes(),        "s+": this.getSeconds(),        "S": this.getMilliseconds(),        "h+": (this.getHours() % 12),        "a": (this.getHours() / 12) <= 1 ? "AM" : "PM"    };    /*遍历正则式pattern类型对象构建returnValue对象*/    for (var key in format) {        var regExp = new RegExp("(" + key + ")");        if (regExp.test(returnValue)) {            var zero = "";            for (var i = 0; i < RegExp.$1.length; i++) { zero += "0"; }            var replacement = RegExp.$1.length == 1 ? format[key] : (zero + format[key]).substring((("" + format[key]).length));            returnValue = returnValue.replace(RegExp.$1, replacement);        }    }    return returnValue;};//翻页-------------------------------------------------------------------------------function turnPage(pageIndex) {    var strWhereVal = $("#strWhere").val()    if ($("#strWhere") == undefined || $("#strWhere") == null ||        $("#strWhere").val() == undefined || $("#strWhere").val() == null)        getDataDrawTable("", pageIndex, UrlAction);    else        getDataDrawTable(strWhereVal, pageIndex, UrlAction);}function homePage() {    turnPage(1);}function previousPage() {    turnPage(parseInt($("#PageIndex").val()) - 1);}function nextPage() {    turnPage(parseInt($("#PageIndex").val()) + 1);}function endPage() {    turnPage(parseInt($("#TotalPages").val()));}function getDataDrawTable(strWhere, pageIndex, actionUrl) {    $.ajax({        url: actionUrl,        data: { strWhere: strWhere, pageIndex: pageIndex },        type: "POST",        dataType: 'text',        success: function (data) {            var pageTable = eval('(' + data + ')');            drawTable(pageTable.DataTable);            MakePagination(pageTable);        },        error: function (xhr, textStatus, error) {            alert(error);        }    });}function ajax(url, param, successFun) {    $.ajax({        url: url,        data: JSON.stringify(param),        contentType: "application/json;charset=UTF-8",        type: "POST",        dataType: "json",        async: true,        error: function (XMLHttpRequest, textStatus, errorThrown) {            artDialog.alert('
url:' + this.url + '
data:' + this.data + '
textStatus:' + textStatus + '
errorThrown:' + errorThrown); }, success: successFun, });}function pagination(page) { var TotalCount = pageTable.TotalCount;//总记录数 var PageSize = pageTable.PageSize;//每页记录数 var HasPreviousPage = pageTable.HasPreviousPage;//是否有上一页 var HasNextPage = pageTable.HasNextPage;//是否有下一页 var PageIndex = pageTable.PageIndex;//当前页 var TotalPages = pageTable.TotalPages;//总页数 $("#PageIndex").val(PageIndex); $("#TotalPages").val(TotalPages); var strHomePagePreviousPage = "首页" + "" + "" + ""; var strNextPageEndPage = "" + "" + "" + "尾页"; strHomePagePreviousPage = HasPreviousPage ? strHomePagePreviousPage : ""; strNextPageEndPage = HasNextPage ? strNextPageEndPage : ""; var strPagination = "
" + "
共 " + TotalCount + " 条记录,每页 " + PageSize + " 条" + "
" + strHomePagePreviousPage + "
" + PageIndex + "/" + TotalPages + "页" + strNextPageEndPage + "
" + "
"; $("#divYeMa").remove(); $("#divTabel").append($(strPagination));}function MakePagination(pageTable) { var TotalCount = pageTable.TotalCount;//总记录数 var PageSize = pageTable.PageSize;//每页记录数 var HasPreviousPage = pageTable.HasPreviousPage;//是否有上一页 var HasNextPage = pageTable.HasNextPage;//是否有下一页 var PageIndex = pageTable.PageIndex;//当前页 var TotalPages = pageTable.TotalPages;//总页数 $("#PageIndex").val(PageIndex); $("#TotalPages").val(TotalPages); var strHomePagePreviousPage = "首页" + "" + "" + ""; var strNextPageEndPage = "" + "" + "" + "尾页"; strHomePagePreviousPage = HasPreviousPage ? strHomePagePreviousPage : ""; strNextPageEndPage = HasNextPage ? strNextPageEndPage : ""; var strPagination = "
" + "
共 " + TotalCount + " 条记录,每页 " + PageSize + " 条" + "
" + strHomePagePreviousPage + "
" + PageIndex + "/" + TotalPages + "页" + strNextPageEndPage + "
" + "
"; $("#divYeMa").remove(); $("#divTabel").append($(strPagination));}//utility-------------------------------------------------------------------------------function removeAll(tableId) {
//清除table已有的内容 $("#" + tableId + " tr:not(:first)").remove();}function GetTable_Remove(tableId) {
//清除table已有的内容 $("#" + tableId + " tr:not(:first)").remove(); return $("#" + tableId);}function format(value) { return value == null ? "" : value;}function formatDate(jsonDate) { if (jsonDate == undefined || jsonDate == null || jsonDate == '') return ''; var strDate = new Date(jsonDate).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '') //var date = new Date(jsonDate.replace(/T/g, ' ')); var date = new Date(strDate); return date.format("yyyy-MM-dd HH:mm");}//2017-06-16T15:51:55.093function formatDate_yMd(jsonDate) { if (jsonDate == undefined || jsonDate == null || jsonDate == '') return ''; var date = new Date(parseInt(jsonDate.toString().replace("/Date(", "").replace(")/", ""), 10)); return date.format("yyyy-MM-dd");}//2017-06-16T15:51:55.093function formatDate2(jsonDate) { if (jsonDate == undefined || jsonDate == null || jsonDate == '') return ''; //var date = new Date(parseInt(jsonDate.toString().replace("/Date(", "").replace(")/", ""), 10)); var date = new Date(parseInt(jsonDate, 10)); return date.format("yyyy-MM-dd HH:mm");}//1497542400000function formatDate3(jsonDate) { if (jsonDate == undefined || jsonDate == null || jsonDate == '') return ''; var date = new Date(parseInt(jsonDate.toString().replace("/Date(", "").replace(")/", ""), 10)); return date.format("yyyy-MM-dd HH:mm");}// /Date(1436595149269)///DataGrid-------------------------------------------------------------------------------function DataGrid(name, url, param, DrawTable, ifPage) { this.name = name; this.url = url; this.param = param; if (!this.param.pageIndex) this.param.pageIndex = 1; if (!this.param.pageSize) this.param.pageSize = 10; this.DrawTable = DrawTable; this.ifPage = ifPage; this.list = {}; this.totalPage = 0;}DataGrid.prototype.load = function () { $.ajax({ url: this.url, data: JSON.stringify(this.param), contentType: "application/json;charset=UTF-8", type: "POST", dataType: "json", async: true, error: function (XMLHttpRequest, textStatus, errorThrown) { artDialog.alert('
url:' + this.url + '
data:' + this.data + '
textStatus:' + textStatus + '
errorThrown:' + errorThrown); }, success: this.produceSuccessFun(), //success: function (data) {
// this.successFun(data); //}, });}DataGrid.prototype.produceSuccessFun = function () { var dataGrid = this; function successFun(data) { dataGrid.list = data.rows; var list = dataGrid.list; var table = GetTable_Remove(dataGrid.name); if (list == null) { var tr = $(""); tr.append($('没有查询到数据')); table.append(tr); } else { dataGrid.DrawTable(table, list); if (dataGrid.ifPage) { var total = data.total; var pageSize = dataGrid.param.pageSize; var pageIndex = dataGrid.param.pageIndex; var HasPreviousPage = pageIndex > 1;//是否有上一页 var TotalPage = Math.ceil(total / pageSize);//总页数 dataGrid.totalPage = TotalPage; var HasNextPage = pageIndex < TotalPage;//是否有下一页 var strHomePagePreviousPage = "首页" + "" + "" + ""; var strNextPageEndPage = "" + "" + "" + "尾页"; strHomePagePreviousPage = HasPreviousPage ? strHomePagePreviousPage : ""; strNextPageEndPage = HasNextPage ? strNextPageEndPage : ""; var strPagination = "
" + "
共 " + total + " 条记录,每页 " + pageSize + " 条" + "
" + strHomePagePreviousPage + "
" + pageIndex + "/" + TotalPage + "页" + strNextPageEndPage + "
" + "
"; table.nextAll().remove(); table.parent().append($(strPagination)); } } } return successFun;};DataGrid.prototype.turnPage = function (pageIndex) { this.param.pageIndex = pageIndex; this.load();}DataGrid.prototype.homePage = function () { this.turnPage(1);}DataGrid.prototype.previousPage = function () { this.turnPage(this.param.pageIndex - 1);}DataGrid.prototype.nextPage = function () { this.turnPage(this.param.pageIndex + 1);}DataGrid.prototype.endPage = function () { this.turnPage(this.totalPage);}/*DataGrid.prototype.reload = function () { this.turnPage(this.param.pageIndex);}*///DataGridJsonParse-------------------------------------------------------------------------------function DataGridJsonParse_Construct(name, url, DrawTable, ifPage) { return new DataGridJsonParse(name, url, {}, DrawTable, ifPage);}//DataGridJsonParse的构造方法function DataGridJsonParsePage(name, url, DrawTable) { return new DataGridJsonParse(name, url, {}, DrawTable, true);}//DataGridJsonParse的构造方法Pagefunction DataGridJsonParse(name, url, param, DrawTable, ifPage) { this.name = name; this.url = url; this.param = param; if (!this.param.pageIndex) this.param.pageIndex = 1; if (!this.param.pageSize) this.param.pageSize = 10; this.DrawTable = DrawTable; this.ifPage = ifPage; this.list = {}; this.totalPage = 0;}//DataGridJsonParse类DataGridJsonParse.prototype.load = function () { $.ajax({ url: this.url, data: JSON.stringify(this.param), contentType: "application/json;charset=UTF-8", type: "POST", dataType: "json", async: true, error: function (XMLHttpRequest, textStatus, errorThrown) { artDialog.alert('
url:' + this.url + '
data:' + this.data + '
textStatus:' + textStatus + '
errorThrown:' + errorThrown); }, success: this.produceSuccessFun(), //success: function (data) {
// this.successFun(data); //}, });}DataGridJsonParse.prototype.produceSuccessFun = function () { var dataGrid = this; function successFun(data) { data = JSON.parse(data); dataGrid.list = data.rows; var list = dataGrid.list; var table = GetTable_Remove(dataGrid.name); if (list == null) { var tr = $(""); tr.append($('没有查询到数据')); table.append(tr); } else { dataGrid.DrawTable(table, list); if (dataGrid.ifPage) { var total = data.total; var pageSize = dataGrid.param.pageSize; var pageIndex = dataGrid.param.pageIndex; var HasPreviousPage = pageIndex > 1;//是否有上一页 var TotalPage = Math.ceil(total / pageSize);//总页数 dataGrid.totalPage = TotalPage; var HasNextPage = pageIndex < TotalPage;//是否有下一页 var strHomePagePreviousPage = "首页" + "" + "" + ""; var strNextPageEndPage = "" + "" + "" + "尾页"; strHomePagePreviousPage = HasPreviousPage ? strHomePagePreviousPage : ""; strNextPageEndPage = HasNextPage ? strNextPageEndPage : ""; var strPagination = "
" + "
共 " + total + " 条记录,每页 " + pageSize + " 条" + "
" + strHomePagePreviousPage + "
" + pageIndex + "/" + TotalPage + "页" + strNextPageEndPage + "
" + "
"; table.nextAll().remove(); table.parent().append($(strPagination)); } } } return successFun;};DataGridJsonParse.prototype.turnPage = function (pageIndex) { this.param.pageIndex = pageIndex; this.load();}DataGridJsonParse.prototype.homePage = function () { this.turnPage(1);}DataGridJsonParse.prototype.previousPage = function () { this.turnPage(this.param.pageIndex - 1);}DataGridJsonParse.prototype.nextPage = function () { this.turnPage(this.param.pageIndex + 1);}DataGridJsonParse.prototype.endPage = function () { this.turnPage(this.totalPage);}//GetByModelId-------------------------------------------------------------------------------function GetByModelId(ModelId, models, IdName) { for (var i = 0; i < models.length; i++) { if (models[i][IdName] == ModelId) return models[i]; } return null;}//工具-------------------------------------------------------------------------------function isNotANumber(inputData) { //isNaN(inputData)不能判断空串或一个空格 //如果是一个空串或是一个空格,而isNaN是做为数字0进行处理的,而parseInt与parseFloat是返回一个错误消息,这个isNaN检查不严密而导致的。 if (parseFloat(inputData).toString() == "NaN") { //alert("请输入数字……");注掉,放到调用时,由调用者弹出提示。 return false; } else { //(parseFloat(inputData).toString() == "NaN"),这种方法不能判断“4e”、“3f”等形式的错误, //所以需加上isNaN if (isNaN(inputData)) { return false; } else { if (inputData == inputData.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3')) { //验证 小数位数 是否没有超过两位 return true; } else { return false; } } }}

 

转载于:https://www.cnblogs.com/xsj891107/p/10820101.html

你可能感兴趣的文章
图片编辑的利器(介绍韩国免费图片工具PhotoScape)
查看>>
Python基础第十一天:递归函数
查看>>
钉钉机器人
查看>>
博雅PHP高级工程师面试题-自拟
查看>>
SQL SERVER 查看表是否存在
查看>>
构建ASP.NET网站十大必备工具
查看>>
a*寻路分析
查看>>
table左边固定-底部横向滚动条-demo
查看>>
MySQL事件异常记录
查看>>
中国创新教育交流会杂感
查看>>
逍遥笔记
查看>>
JSON 命令行工具
查看>>
ubuntu 查看软件包中的内容 (已经安装)
查看>>
iperf 一个测试网络吞吐的工具
查看>>
IOR and mdtest - measure parallel file system I/O performance at both the POSIX and MPI-IO level.
查看>>
文件系统测试工具整理
查看>>
好用的性能检测工具 - Glances
查看>>
tcp滑动窗口和读写缓冲区
查看>>
GO 使用静态链接库编译 生成可执行文件 使用第三方 .a 文件,无源码构造
查看>>
ssh 使用指定网卡 连接特定网络
查看>>