Browse Source

更新时间戳转换工具

zxlie 6 years ago
parent
commit
c765fdc124

+ 1 - 1
apps/manifest.json

@@ -1,6 +1,6 @@
 {
   "name": "WEB前端助手(FeHelper)",
-  "version": "2018.12.0422",
+  "version": "2018.12.1115",
   "manifest_version": 2,
   "default_locale": "zh_CN",
   "description": "FE助手:包括JSON格式化、二维码生成与解码、信息编解码、代码压缩、美化、页面取色、Markdown与HTML互转、网页滚动截屏、正则表达式、时间转换工具、编码规范检测、页面性能检测、Ajax接口调试、密码生成器、JSON比对工具、网页编码设置、便签笔记",

+ 4 - 1
apps/static/js/utils.js

@@ -91,7 +91,8 @@ Date.prototype.format = function (pattern) {
         date2 = this.getDate(),
         hours = this.getHours(),
         minutes = this.getMinutes(),
-        seconds = this.getSeconds();
+        seconds = this.getSeconds(),
+        milliSec = this.getMilliseconds();
 
     replacer(/yyyy/g, pad(year, 4));
     replacer(/yy/g, pad(parseInt(year.toString().slice(2), 10), 2));
@@ -108,6 +109,8 @@ Date.prototype.format = function (pattern) {
     replacer(/m/g, minutes);
     replacer(/ss/g, pad(seconds, 2));
     replacer(/s/g, seconds);
+    replacer(/SSS/g, pad(milliSec,3));
+    replacer(/S/g, milliSec);
 
     return pattern;
 };

BIN
apps/static/screenshot/wx-qrcode-fehelper-group.png


+ 18 - 0
apps/timestamp/index.css

@@ -23,4 +23,22 @@
 
 .mod-time-input{
     width: 80px;
+}
+.x-sel-sec {
+    display: inline-block;
+    width: 80px;
+}
+.x-wd {
+    margin-top: 30px;
+    border-bottom: 1px solid #eee;
+    padding-bottom: 5px;
+    font-size: 16px;
+    color: #428bca;
+}
+.x-cnt {
+    padding:0 15px;
+}
+thead th {
+    text-align: center;
+    background: #f9f9f9;
 }

File diff suppressed because it is too large
+ 0 - 0
apps/timestamp/index.html


+ 28 - 7
apps/timestamp/index.js

@@ -1,6 +1,8 @@
 /**
  * FeHelper Timestamp Tools
  */
+
+Tarp.require('../static/js/utils');
 new Vue({
     el: '#pageContainer',
     data: {
@@ -9,16 +11,31 @@ new Vue({
         txtSrcStamp: '',
         txtDesDate: '',
         txtLocale: '',
-        txtDesStamp: ''
+        txtDesStamp: '',
+        secFrom: 's',
+        secTo: 's',
+        worldTime: {}
     },
     mounted: function () {
         this.startTimestamp();
     },
     methods: {
         startTimestamp: function () {
+            let formatter = 'yyyy-MM-dd HH:mm:ss';
             window.intervalId = window.setInterval(() => {
-                this.txtNowDate = (new Date()).toLocaleString();
-                this.txtNow = Math.round((new Date()).getTime() / 1000);
+                let localDate = new Date();
+
+                this.txtNowDate = localDate.format(formatter);
+                this.txtNow = Math.round(localDate.getTime() / 1000) + ' s   / ' + localDate.getTime() + ' ms';
+
+                let gmtTime = new Date(localDate.getTime() + localDate.getTimezoneOffset() * 60000);
+                this.worldTime['local'] = this.txtNowDate;
+                this.worldTime['gmt'] = gmtTime.format(formatter);
+
+                for (let offset = -12; offset <= 12; offset++) {
+                    this.worldTime[ offset > 0 ? ('+' + offset) : offset] = new Date(gmtTime.getTime() + offset * 60 * 60000).format(formatter);
+                }
+
             }, 1000);
         },
         unixToggle: function () {
@@ -34,7 +51,6 @@ new Vue({
             }
         },
         stampToLocale: function () {
-            Tarp.require('../static/js/utils');
             if (this.txtSrcStamp.length === 0) {
                 alert('请先填写你需要转换的Unix时间戳');
                 return;
@@ -43,17 +59,22 @@ new Vue({
                 alert('请输入合法的Unix时间戳');
                 return;
             }
-            this.txtDesDate = (new Date(parseInt(this.txtSrcStamp, 10) * 1000)).format('yyyy-MM-dd HH:mm:ss');
+
+            let base = this.secFrom === 's' ? 1000 : 1;
+            let format = 'yyyy-MM-dd HH:mm:ss' + (this.secFrom === 's' ? '' : ':SSS');
+
+            this.txtDesDate = (new Date(parseInt(this.txtSrcStamp, 10) * base)).format(format);
         },
         localeToStamp: function () {
-            if(this.txtLocale && !/\s\d+:\d+:\d+/.test(this.txtLocale)) {
+            if (this.txtLocale && !/\s\d+:\d+:\d+/.test(this.txtLocale)) {
                 this.txtLocale += ' 00:00:00';
             }
             let locale = Date.parse(this.txtLocale);
             if (isNaN(locale)) {
                 alert('请输入合法的时间格式,如:2014-04-01 10:01:01,或:2014-01-01');
             }
-            this.txtDesStamp = locale / 1000;
+            let base = this.secTo === 's' ? 1000 : 1;
+            this.txtDesStamp = Math.round(locale / base);
         }
     }
 });

Some files were not shown because too many files changed in this diff