index.html 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8"/>
  5. <title>Krajee JQuery Plugins - &copy; Kartik</title>
  6. <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
  7. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
  8. <script src="../js/php-date-formatter.js" type="text/javascript"></script>
  9. </head>
  10. <body>
  11. <div style="margin:50px;padding:0 30px;border:3px double #ddd;border-radius:8px">
  12. <div class="page-header">
  13. <h1 class="text-info">PHP Date Formatter Demo
  14. <small>&copy; Krajee Solutions</small>
  15. </h1>
  16. </div>
  17. <form class="form-vertical">
  18. <div class="form-group">
  19. <div class="row">
  20. <div class="col-sm-4">
  21. <label class="control-label">Date String</label>
  22. <input id="kv-1" value="" class="form-control">
  23. </div>
  24. <div class="col-sm-4">
  25. <label class="control-label">Source Format</label>
  26. <input id="kv-2" value="Y-m-d H:i:s" class="form-control">
  27. </div>
  28. <div class="col-sm-4">
  29. <label class="control-label">Display Format</label>
  30. <input id="kv-3" value="D, M jS, Y g:i:s A" class="form-control">
  31. </div>
  32. </div>
  33. </div>
  34. <div class="form-group">
  35. <div class="row">
  36. <div class="col-sm-8">
  37. <label class="control-label">Parsed Date</label>
  38. <input id="kv-4" class="form-control" readonly>
  39. </div>
  40. <div class="col-sm-4">
  41. <label class="control-label">Formatted Date</label>
  42. <input id="kv-5" class="form-control" readonly>
  43. </div>
  44. </div>
  45. </div>
  46. </form>
  47. <h4>Date Format Results</h4>
  48. <div id="formats">
  49. </div>
  50. </div>
  51. </body>
  52. <script>
  53. var fmt = new DateFormatter(),
  54. fmts = [
  55. 'd', 'D', 'j', 'l', 'N', 'w', 'z', 'W', 'F', 'm', 'M', 'n', 't', 'L', 'o',
  56. 'Y', 'y', 'a', 'A', 'B', 'g', 'G', 'h', 'H', 'i', 's', 'u', 'e', 'I', 'O', 'P',
  57. 'T', 'Z', 'c', 'r', 'U'
  58. ], setFmt = function() {
  59. var out = '', d1, d2;
  60. d1 = fmt.parseDate($("#kv-1").val(), $("#kv-2").val());
  61. $("#kv-4").val(d1);
  62. d2 = fmt.formatDate(d1, $("#kv-3").val());
  63. $("#kv-5").val(d2);
  64. if (!d1) {
  65. $('#formats').html('<div class="alert alert-danger"><h4>Error</h4>Cannot parse source date</div>');
  66. return;
  67. }
  68. $.each(fmts, function(i, f) {
  69. out += '<tr><td><code>' + f + '</code></td><td><samp>' + fmt.parseFormat(f, d1) + '</samp></td></tr>';
  70. });
  71. $('#formats').html('<table class="table table-bordered table-hover"><tr class="active"><th>Format</th><th>Value</th></tr>' + out + '</table>');
  72. };
  73. $(document).on('ready', function () {
  74. var initDate = fmt.formatDate(new Date(), $("#kv-2").val());
  75. $('#kv-1').val(initDate);
  76. setFmt();
  77. });
  78. $("#kv-1,#kv-2,#kv-3").on("change", function () {
  79. setFmt();
  80. });
  81. </script>
  82. </html>