dateformat.html 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Date Format - jQuery EasyUI Demo</title>
  6. <link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
  7. <link rel="stylesheet" type="text/css" href="../../themes/icon.css">
  8. <link rel="stylesheet" type="text/css" href="../demo.css">
  9. <script type="text/javascript" src="../../jquery.min.js"></script>
  10. <script type="text/javascript" src="../../jquery.easyui.min.js"></script>
  11. </head>
  12. <body>
  13. <h2>Date Format</h2>
  14. <p>Different date formats are applied to different DateBox components.</p>
  15. <div style="margin:20px 0;"></div>
  16. <div class="easyui-panel" style="width:100%;max-width:400px;padding:30px 60px;">
  17. <div style="margin-bottom:20px">
  18. <input class="easyui-datebox" label="Default Format:" labelPosition="top" style="width:100%;">
  19. </div>
  20. <div style="margin-bottom:20px">
  21. <input class="easyui-datebox" label="Customized Format:" labelPosition="top" data-options="formatter:myformatter,parser:myparser" style="width:100%;">
  22. </div>
  23. </div>
  24. <script type="text/javascript">
  25. function myformatter(date){
  26. var y = date.getFullYear();
  27. var m = date.getMonth()+1;
  28. var d = date.getDate();
  29. return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
  30. }
  31. function myparser(s){
  32. if (!s) return new Date();
  33. var ss = (s.split('-'));
  34. var y = parseInt(ss[0],10);
  35. var m = parseInt(ss[1],10);
  36. var d = parseInt(ss[2],10);
  37. if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
  38. return new Date(y,m-1,d);
  39. } else {
  40. return new Date();
  41. }
  42. }
  43. </script>
  44. </body>
  45. </html>