currenttime.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
  6. <script type="text/javascript" src="../../script/jquery.min.js"></script>
  7. <script type="text/javascript" src="../../script/semantic/semantic.min.js"></script>
  8. <title>Current Time</title>
  9. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  10. </head>
  11. <body>
  12. <div class="ui segment">
  13. <h3 class="ui header">Current system time:</h3>
  14. <p id="currenttime"></p>
  15. <p style="font-size:10px" id="lagging"></p>
  16. <div class="ui accordion">
  17. <div class="title">
  18. <i class="dropdown icon"></i> More Calandar
  19. </div>
  20. <div class="content">
  21. <div class="ui two column grid" id="additionalCalendar">
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. </body>
  27. <script>
  28. $('.ui.accordion')
  29. .accordion();
  30. //Init variable
  31. var d = new Date();
  32. var ClienttimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
  33. var options = {
  34. year: 'numeric',
  35. month: 'long',
  36. day: 'numeric',
  37. hour: 'numeric',
  38. minute: 'numeric',
  39. second: 'numeric',
  40. timeZoneName: 'long',
  41. //timeZone: timeZone,
  42. hour12: true
  43. };
  44. //Startup
  45. if (typeof uT !== "undefined") {
  46. clearInterval(uT);
  47. }
  48. if (typeof uTfs !== "undefined") {
  49. clearInterval(uTfs);
  50. }
  51. setTimeout(function() {
  52. d = new Date();
  53. updateTime();
  54. updateTimeFromServer();
  55. var uT = setInterval(updateTime, 1000);
  56. var uTfS = setInterval(updateTimeFromServer, 10000);
  57. }, 1000 - new Date().getMilliseconds());
  58. function updateTime() {
  59. d.setSeconds(d.getSeconds() + 1);
  60. var formattedDate = new Intl.DateTimeFormat(navigator.language, options).format(d);
  61. $("#currenttime").text(formattedDate);
  62. }
  63. function updateTimeFromServer() {
  64. $.getJSON("/system/time/getTime", function(data) {
  65. options.timeZone = data["timezone"];
  66. d = new Date(data["time"]);
  67. console.log(d);
  68. var timeDiff = new Date() - d;
  69. console.log(timeDiff);
  70. if (timeDiff > 0) {
  71. $("#lagging").text("Server is lagging " + formatTime(timeDiff) + " behind.");
  72. } else {
  73. $("#lagging").text("Server is " + formatTime(timeDiff) + " faster than your computer.")
  74. }
  75. updateAdditionalCalander();
  76. });
  77. if ($("#currenttime").length == 0) {
  78. clearInterval(uT);
  79. clearInterval(uTfs);
  80. }
  81. }
  82. function formatTime(time) {
  83. if (time < 1000) {
  84. return time + "ms";
  85. } else if (time < 60000) {
  86. return Math.floor(time / 1000) + "s " + convert(time - Math.floor(time / 1000) * 1000);
  87. } else if (timediff < 3600000) {
  88. return Math.floor(time / 60000) + "m " + convert(time - Math.floor(time / 60000) * 60000);
  89. } else if (timediff < 216000000) { //original was 216000000
  90. return Math.floor(time / 3600000) + "h " + convert(time - Math.floor(time / 3600000) * 3600000);
  91. }
  92. }
  93. /* Additional Calendar */
  94. //Data followed by https://github.com/unicode-org/cldr/blob/2dd06669d833823e26872f249aa304bc9d9d2a90/common/bcp47/calendar.xml
  95. function updateAdditionalCalander() {
  96. var AddOption = {
  97. year: 'numeric',
  98. month: 'numeric',
  99. day: 'numeric',
  100. };
  101. var lang = navigator.language;
  102. var additionalCalendarList = ["buddhist", "chinese", "coptic", "dangi", "ethioaa", "ethiopic", "gregory", "hebrew", "indian", "islamic", "islamic-umalqura", "islamic-tbla", "islamic-civil", "islamic-rgsa", "iso8601", "japanese", "persian", "roc"];
  103. var additionalCalendarDList = ["Thai Buddhist calendar", "Traditional Chinese calendar", "Coptic calendar", "Traditional Korean calendar", "Ethiopic calendar, Amete Alem", "Ethiopic calendar, Amete Mihret", "Gregorian calendar", "Traditional Hebrew calendar", "Indian calendar", "Islamic calendar", "Islamic calendar, Umm al-Qura", "Islamic calendar, tabular (astronomical epoch)", "Islamic calendar, tabular (civil epoch)", "Islamic calendar, Saudi Arabia sighting", "ISO calendar", "Japanese Imperial calendar", "Persian calendar", "Republic of China calendar"];
  104. var htmlstr = "";
  105. for (i = 0; i < additionalCalendarList.length; i++) {
  106. var formattedDate = new Intl.DateTimeFormat(lang + "-u-ca-" + additionalCalendarList[i], AddOption).format(d);
  107. htmlstr += '<div class="column">' + additionalCalendarDList[i] + ": " + '</div>'
  108. htmlstr += '<div class="column">' + formattedDate + '</div>'
  109. }
  110. $("#additionalCalendar").html(htmlstr);
  111. }
  112. </script>
  113. </html>