"Easyui" date formatting

Source: Internet
Author: User
Tags file info

This paper has been tested to solve the problem of getFullYear () is not a function, etc.

The effect is as follows:

First of all:

The fields in Oracle are set to Date,mysql in Datetime,mybatis and are automatically mapped to timestamp;

Secondly:

The field in the Model entity class uses SQL. Timestamp, if set to the date type, then the hours and seconds will be displayed as 00:00:00, which is obviously meaningless.

1 function Formatterdate (val, row) {2     if(val! =NULL) {3var date =NewDate (val);4         returnDate.getfullyear () + '-' + (Date.getmonth () + 1) + '-'5+date.getdate ();6     }7 }8 /**9 * formatted date (not including time)Ten  */ One function Formatterdate1 (val, row) { A     if(val! =NULL) { -var date =NewDate (val); -         returndate.getfullyear () the+ "-"//"Year" -+ ((date.getmonth () + 1) > 10? (Date.getmonth () + 1): "0" -+ (Date.getmonth () + 1)) + "-"//"Month" -+ (Date.getdate () < 10? "0" +date.getdate (): Date.getdate ()); +     } - } + /** A * Formatted date (with time "00:00:00") at  */ - function Formatterdate2 (val, row) { -     if(val! =NULL) { -var date =NewDate (val); -         returndate.getfullyear () -+ "-"//"Year" in+ ((date.getmonth () + 1) > 10? (Date.getmonth () + 1): "0" -+ (Date.getmonth () + 1)) + "-"//"Month" to+ (Date.getdate () < 10? "0" +date.getdate (): Date.getdate ()) ++ "" + "00:00:00"; -     } the } * /** $ * formatted to date (including time)Panax Notoginseng  */ - function Formatterdate3 (val, row) { the     if(val! =NULL) { +var date =NewDate (val); A         returndate.getfullyear () the+ "-"//"Year" ++ ((date.getmonth () + 1) > 10? (Date.getmonth () + 1): "0" -+ (Date.getmonth () + 1)) $+ "-"//"Month" $+ (Date.getdate () < 10? "0" +date.getdate (): Date.getdate ()) -+ " " -+ (Date.gethours () < 10? "0" +date.gethours (): Date the . GetHours ()) -+ ":"Wuyi+ (Date.getminutes () < 10? "0" +date.getminutes (): Date the . getminutes ()) -+ ":" Wu+ (Date.getseconds () < 10? "0" +date.getseconds (): Date - . getseconds ()); About     } $}
View Code
The above is Common.js, which is introduced into the JSP file that needs to be used.
1<%@ page language= "Java"Import= "java.util.*" pageencoding= "UTF-8"%>2<%3String Path =Request.getcontextpath ();4String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";5%>6<! DOCTYPE html>789<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">Ten<title>file info</title> One<link rel= "stylesheet" type= "Text/css" href= ". /jquery-easyui-1.4.1/themes/default/easyui.css "> A<link rel= "stylesheet" type= "Text/css" href= ". /jquery-easyui-1.4.1/themes/icon.css "> -<link rel= "stylesheet" type= "Text/css" href= ". /jquery-easyui-1.4.1/themes/color.css "> -<link rel= "stylesheet" type= "Text/css" href= ". /jquery-easyui-1.4.1/demo/demo.css "> the<link rel= "stylesheet" type= "Text/css" href= ". /css/info.css "> -<script type= "Text/javascript" src= ". /jquery-easyui-1.4.1/jquery.min.js "></script> -<script type= "Text/javascript" src= ". /jquery-easyui-1.4.1/jquery.easyui.min.js "></script> -<script type= "Text/javascript" src= ". /jquery-easyui-1.4.1/locale/easyui-lang-zh_cn.js "></script> +<!--<script type= "Text/javascript" src= ". /js/jquery-1.8.0.min.js "></script> -<script type= "Text/javascript" src= ". /js/common.js "></script> + A<body> at<!--display a table of file information-- -<table id= "DG"class= "Easyui-datagrid" style= "height:470px;" -Url= "Findall.do" -Toolbar= "#toolbar" pagination= "true" -Rownumbers= "true" fitcolumns= "true" singleselect= "true" -data-options= "fit:false,border:false,pagesize:5,pagelist:[5,10,15,20" > in<thead> -<tr> to<!--must be consistent with entity class fields-- +<th field= "filename" width= "> File name </th> -<th field= "filepath" width= "> File path </th> the<th field= "updatedate" width= "> Upload time </th> *</tr> $</thead>Panax Notoginseng</table> -<table id= "Tdlist" ></table> the<script type= "Text/javascript" > +var $jq =jquery.noconflict (); A $jq (function () { the$JQ ("#tdList"). DataGrid ({ +URL: "Findall.do",                -Title: "Data Dictionary list", $Loadmsg: ' Loading information ... ', $Width: "100%",                -IDfield: "Id",                -Fitcolumns:true, thePagination:true, -Pagesize:10,WuyiPageList: [10, 20, 35, 50],                theSingleselect:true, -Rownumbers:true, Wu columns: [[ -{field: ' filename ', title: ' File name ', width:120 },                 About{field: ' filepath ', title: ' File path ', width:80 },                    $                     { -Field: ' Updatedate ', title: ' Upload Time ', width:80,                            - Formatter:formatterdate3 -                     } A   +             ]], the toolbar: [{ -ID: ' Add ', $Text: ' Add ', theIconcls: ' Icon-add ', the Handler:add the             }], the onloadsuccess:function (data) { -                 if(!data.rows) { invar BODY = $JQ ( This). Data (). Datagrid.dc.body2; theBody.find (' Table Tbody '). Append (' <tr><td width= ' + body.width () + ' style= ' height:25px; text-align:center; " > No Data </td></tr> '); the                 } About             } the         }); the     }); the              +   - function Add () { the$JQ ("#add"). dialog ({BayiTitle: "Add Data dictionary category", theCollapsible:true, theMinimizable:true, -Maximizable:true, -Resizable:true, thewidth:400, theheight:260, the buttons: [{ theText: "Save", -ICONCLS: "Icon-add", the handler:function () { the$JQ ("#add form"). Submit (); the                 }94             }, { theText: "Cancel", theICONCLS: "Icon-cancel", the handler:function () {98$JQ ("#add"). Dialog ("Close"); About                 } -             }]101         });102     };103     104</script> the</body>106View Code

The above is the JSP code.

Thanks to other bloggers for their valuable algorithms and suggestions.

"Easyui" date formatting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.