OSDN Git Service

js: add nsUtil object to base.js
authorhylom <hylom@users.sourceforge.jp>
Fri, 21 Apr 2017 14:47:08 +0000 (23:47 +0900)
committerhylom <hylom@users.sourceforge.jp>
Fri, 21 Apr 2017 14:47:08 +0000 (23:47 +0900)
src/newslash_web/public/js/base.js

index ac54130..57706a6 100644 (file)
@@ -26,4 +26,29 @@ var Contents = function() {
   // for internal use
   this.editing = true;
 };
+
+var nsUtil = {
+  toDateTimeLocal: function toDateTimeLocal(date) {
+    function pad(number) {
+      return (number < 10) ? ('0' + number) : number;
+    }
+
+    return date.getUTCFullYear() +
+      '-' + pad(date.getMonth() + 1) +
+      '-' + pad(date.getDate()) +
+      'T' + pad(date.getHours()) +
+      ':' + pad(date.getMinutes()) +
+      ':' + pad(date.getSeconds());
+  },
+  formatDateTime: function formatDateTime(dtString) {
+    var offset = 9;
+    var utcString = dtString + "+00:00";
+    var date = new Date(utcString);
+    return date.getUTCFullYear() +
+      '年' + (date.getMonth() + 1) +
+      '月' + (date.getDate()) +
+      '日' + (date.getHours()) +
+      '時' + (date.getMinutes());
+  },
+};
+