From b33dac77467a88da539b15f35b47b6da73f2c252 Mon Sep 17 00:00:00 2001
From: Frost-ZX <30585462+Frost-ZX@users.noreply.github.com>
Date: Tue, 15 Oct 2019 23:45:49 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=20Unix=20=E6=97=B6=E9=97=B4?=
=?UTF-8?q?=E6=88=B3=E8=BD=AC=E6=8D=A2=E5=B7=A5=E5=85=B7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/css/tool.css | 108 +++++++++++++++++++++-----------------------
docs/index.html | 2 +-
docs/js/tool.js | 73 +++++++++++++++++++-----------
docs/js/tool.min.js | 11 +++--
docs/tool.html | 33 ++++++++++++--
5 files changed, 134 insertions(+), 93 deletions(-)
diff --git a/docs/css/tool.css b/docs/css/tool.css
index e6a0001..3657911 100644
--- a/docs/css/tool.css
+++ b/docs/css/tool.css
@@ -4,11 +4,9 @@
margin: 0;
padding: 0;
}
-
html {
scroll-behavior: smooth;
}
-
body {
padding: 20px 0 50px 0;
background-color: #F5F5F5;
@@ -52,7 +50,6 @@ body {
width: 90%;
max-width: 400px;
}
-
.main > div {
margin: 20px 0;
padding: 15px;
@@ -62,7 +59,6 @@ body {
background-color: #FFF;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
-
.main > div header {
margin-bottom: 10px;
text-align: center;
@@ -70,11 +66,9 @@ body {
font-weight: bold;
user-select: none;
}
-
.main > div input:focus {
outline: none;
}
-
.main > div textarea {
padding: 5px;
box-sizing: border-box;
@@ -83,11 +77,9 @@ body {
box-shadow: 0 0 5px rgba(3, 169, 244, 0.2);
font-size: 14px;
}
-
.main > div textarea:focus {
outline: none;
}
-
.tool-button {
display: inline-block;
user-select: none;
@@ -100,52 +92,16 @@ body {
box-shadow: 2px 2px 5px rgba(3, 169, 244, 0.4);
transition: background 0.2s;
}
-
.tool-button:hover {
background-color: #2196F3;
}
-/* Unix 时间戳转换 */
-
-#tool-unixtime > div {
- user-select: none;
-}
-
-#tool-unixtime > div > span {
- display: inline-block;
- width: 100px;
- text-align: right;
- font-size: 14px;
- font-weight: bold;
-}
-
-#tool-unixtime > p {
- text-align: center;
- font-size: 16px;
- font-weight: bold;
-}
-
-#tool-unixtime input[type="text"] {
- width: 160px;
- border: 1px solid #03A9F4;
- font-size: 14px;
-}
-
-#tool-unixtime label {
- font-size: 14px;
-}
-
-#tool-unixtime .tool-button {
- margin: 5px 5px 2px 0;
-}
-
-/* 导航 */
+/* 索引 */
.tool-nav ul li {
display: inline-block;
list-style: none;
}
-
.tool-nav ul li a {
display: block;
float: left;
@@ -157,29 +113,74 @@ body {
color: #FFF;
transition: background 0.2s;
}
-
.tool-nav ul li a:hover {
background-color: #8BC34A;
}
-
.tool-nav-link {
margin: 0 auto;
box-sizing: border-box;
width: 100%;
}
-/* 计算 */
+/* Unix 时间戳转换 */
+#tool-unixtime > div {
+ user-select: none;
+}
+#tool-unixtime > div > span {
+ display: inline-block;
+ width: 100px;
+ text-align: right;
+ font-size: 14px;
+ font-weight: bold;
+}
+#tool-unixtime > p {
+ text-align: center;
+ font-size: 16px;
+ font-weight: bold;
+}
+#tool-unixtime input[type="text"] {
+ width: 160px;
+ border: 1px solid #03A9F4;
+ font-size: 14px;
+}
+#tool-unixtime label {
+ font-size: 14px;
+}
+#tool-unixtime .tool-button {
+ margin: 5px 5px 2px 0;
+}
+
+/* 计算下载用时 */
+#tool-downloadtime {
+
+}
+#tool-downloadtime-input {
+ padding: 0 0 10px 0;
+ border-bottom: 1px solid #EEE;
+}
+#tool-downloadtime-output {
+ padding: 10px 0;
+ border-bottom: 1px solid #EEE;
+}
+#tool-downloadtime .tool-button {
+ margin: 10px 5px 10px 0;
+}
+#tool-downloadtime-help {
+ padding: 10px 0 0 0;
+ border-top: 1px solid #EEE;
+ font-size: 14px;
+}
+
+/* 简易计算 */
#tool-calculate textarea {
resize: vertical;
font-size: 16px;
}
-
#tool-calculate-tofixed {
width: 20px;
font-size: 14px;
}
-
#tool-calculate .tool-button {
margin: 5px 5px 2px 0;
}
@@ -190,7 +191,6 @@ body {
height: 0;
border: 0.5px solid #EEE;
}
-
#tool-genlink-link input {
margin-bottom: 10px;
padding: 0 2px;
@@ -198,25 +198,20 @@ body {
width: 80%;
border: 1px solid #03A9F4;
}
-
#tool-genlink-settings {
user-select: none;
font-size: 14px;
}
-
#tool-genlink-settings > div {
margin: 5px 0;
}
-
#tool-genlink-settings input[type="text"] {
width: 25px;
font-size: 14px;
}
-
#tool-genlink .tool-button {
margin: 10px 5px 10px 0;
}
-
#tool-genlink textarea {
resize: vertical;
font-size: 14px;
@@ -229,7 +224,6 @@ body {
font-family: monospace;
font-size: 14px;
}
-
#tool-runjs .tool-button {
margin: 5px 5px 0 0;
}
diff --git a/docs/index.html b/docs/index.html
index d19de67..49224b7 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -20,7 +20,7 @@
diff --git a/docs/js/tool.js b/docs/js/tool.js
index aede968..b6b4408 100644
--- a/docs/js/tool.js
+++ b/docs/js/tool.js
@@ -2,38 +2,45 @@
/* Unix 时间戳转换 */
/* --------------- */
-// 函数:获取时间戳 //
-function toolUnixTimeGetNowA(TimeSet, SettingBA, SettingBB) {
- var Time = new Date(); // 创建 Date 对象
- // 若已设定参数 TimeSet,则根据 TimeSet 设置时间 //
- if (TimeSet != '') {
- Time.setFullYear(TimeSet.substring(0, 4)); // TimeSet 的子串:年
- Time.setMonth(TimeSet.substring(5, 7) - 1); // TimeSet 的子串:月
- Time.setDate(TimeSet.substring(8, 10)); // TimeSet 的子串:日
- Time.setHours(TimeSet.substring(11, 13)); // TimeSet 的子串:时
- Time.setMinutes(TimeSet.substring(14, 16)); // TimeSet 的子串:分
- Time.setSeconds(TimeSet.substring(17, 19)); // TimeSet 的子串:秒
- // console.log(Time)
- }
- if (TimeSet != '' && SettingBA == true && SettingBB == false) {
+// 函数:将传入的时间转换为时间戳 //
+function toolUnixTimeToUnix(GetTime, isMillisecond) {
+ var Time = new Date(); // 创建 Date 对象
+ // 根据 GetTime 设置时间 //
+ Time.setFullYear(GetTime.substring(0, 4)); // GetTime 的子串:年
+ Time.setMonth(GetTime.substring(5, 7) - 1); // GetTime 的子串:月
+ Time.setDate(GetTime.substring(8, 10)); // GetTime 的子串:日
+ Time.setHours(GetTime.substring(11, 13)); // GetTime 的子串:时
+ Time.setMinutes(GetTime.substring(14, 16)); // GetTime 的子串:分
+ Time.setSeconds(GetTime.substring(17, 19)); // GetTime 的子串:秒
+ // 调试 //
+ // console.log("时间:" + Time);
+ // 根据 isMillisecond 确认输出的单位
+ if (isMillisecond == false) {
// 模式:秒 //
- var TextLength = Time.getTime().toString().length;
+ var TextLength = Time.getTime().toString().length; // 获取字符串长度
return Time.getTime().toString().substring(0, TextLength - 3); // 返回时间戳
- } else if (TimeSet != '' && SettingBA == false && SettingBB == true) {
+ } else if (isMillisecond == true) {
// 模式:毫秒 //
- var TextLength = Time.getTime().toString().length;
+ var TextLength = Time.getTime().toString().length; // 获取字符串长度
return Time.getTime().toString().substring(0, TextLength - 3) + "000"; // 返回时间戳
} else {
- return Time.getTime(); // 返回时间戳
+ return "模式有误!";
}
}
-// 函数:获取时间 //
-function toolUnixTimeGetNowB(TimeSet) {
+// 函数:将传入的时间戳转换为时间 //
+function toolUnixTimeToTime(GetUnix, isMillisecond) {
var Time = new Date(); // 创建 Date 对象
- // 若已设定参数 TimeSet,则根据 TimeSet 设置时间 //
- if (TimeSet != '') {
- Time.setTime(TimeSet);
+ // 根据 isMillisecond 确认输入的单位
+ if (isMillisecond == false) {
+ // 模式:秒 //
+ GetUnix = GetUnix + "000"; // 补零变为毫秒
+ Time.setTime(GetUnix); // 根据 GetUnix 设置时间
+ } else if (isMillisecond == true) {
+ // 模式:毫秒 //
+ Time.setTime(GetUnix); // 根据 GetUnix 设置时间
+ } else {
+ Time.setTime("0"); // 把时间设置为 0
}
var TimeYear = Time.getFullYear(); // 年
var TimeMonth = Time.getMonth() + 1; // 月
@@ -74,8 +81,14 @@ function toolUnixTimeNow() {
var GetSettingBA = document.getElementById("unixtime-setting-ba").checked; // B 模式:秒
var GetSettingBB = document.getElementById("unixtime-setting-bb").checked; // B 模式:毫秒
// 调用函数,获取时间 //
- GetInputA.value = toolUnixTimeGetNowA('', GetSettingAA, GetSettingAB); // 时间戳
- GetInputB.value = toolUnixTimeGetNowB('', GetSettingBA, GetSettingBB); // 时间
+ if (GetSettingAA == true) {
+ var Time = new Date(); // 创建 Date 对象
+ var TextLength = Time.getTime().toString().length; // 获取字符串长度
+ GetInputA.value = Time.getTime().toString().substring(0, TextLength - 3); // 时间戳(秒)
+ } else if (GetSettingAB == true) {
+ GetInputA.value = new Date().getTime(); // 时间戳(毫秒)
+ }
+ GetInputB.value = toolUnixTimeToTime(new Date().getTime(), true); // 时间
}
// 按钮:转换 //
@@ -89,8 +102,14 @@ function toolUnixTimeSubmit() {
var GetSettingBA = document.getElementById("unixtime-setting-ba").checked; // B 模式:秒
var GetSettingBB = document.getElementById("unixtime-setting-bb").checked; // B 模式:毫秒
// 调用函数,转换时间 //
- GetOutputA.value = toolUnixTimeGetNowB(GetInputA.value, GetSettingAA, GetSettingAB); // 转换为时间
- GetOutputB.value = toolUnixTimeGetNowA(GetInputB.value, GetSettingBA, GetSettingBB); // 转换为时间戳
+ if (GetSettingAA == true) {
+ // 秒 //
+ GetOutputA.value = toolUnixTimeToTime(GetInputA.value, false); // 转换为时间
+ } else if (GetSettingAB == true) {
+ // 毫秒 //
+ GetOutputA.value = toolUnixTimeToTime(GetInputA.value, GetSettingAB); // 转换为时间
+ }
+ GetOutputB.value = toolUnixTimeToUnix(GetInputB.value, GetSettingBB); // 转换为时间戳
}
// 按钮:重置 //
diff --git a/docs/js/tool.min.js b/docs/js/tool.min.js
index 392feb9..278b3e9 100644
--- a/docs/js/tool.min.js
+++ b/docs/js/tool.min.js
@@ -1,14 +1,15 @@
-function toolUnixTimeGetNowA(TimeSet,SettingBA,SettingBB){var Time=new Date();if(TimeSet!=''){Time.setFullYear(TimeSet.substring(0,4));Time.setMonth(TimeSet.substring(5,7)-1);Time.setDate(TimeSet.substring(8,10));Time.setHours(TimeSet.substring(11,13));Time.setMinutes(TimeSet.substring(14,16));Time.setSeconds(TimeSet.substring(17,19));}
-if(TimeSet!=''&&SettingBA==true&&SettingBB==false){var TextLength=Time.getTime().toString().length;return Time.getTime().toString().substring(0,TextLength-3);}else if(TimeSet!=''&&SettingBA==false&&SettingBB==true){var TextLength=Time.getTime().toString().length;return Time.getTime().toString().substring(0,TextLength-3)+"000";}else{return Time.getTime();}}
-function toolUnixTimeGetNowB(TimeSet){var Time=new Date();if(TimeSet!=''){Time.setTime(TimeSet);}
+function toolUnixTimeToUnix(GetTime,isMillisecond){var Time=new Date();Time.setFullYear(GetTime.substring(0,4));Time.setMonth(GetTime.substring(5,7)-1);Time.setDate(GetTime.substring(8,10));Time.setHours(GetTime.substring(11,13));Time.setMinutes(GetTime.substring(14,16));Time.setSeconds(GetTime.substring(17,19));if(isMillisecond==false){var TextLength=Time.getTime().toString().length;return Time.getTime().toString().substring(0,TextLength-3);}else if(isMillisecond==true){var TextLength=Time.getTime().toString().length;return Time.getTime().toString().substring(0,TextLength-3)+"000";}else{return"模式有误!";}}
+function toolUnixTimeToTime(GetUnix,isMillisecond){var Time=new Date();if(isMillisecond==false){GetUnix=GetUnix+"000";Time.setTime(GetUnix);}else if(isMillisecond==true){Time.setTime(GetUnix);}else{Time.setTime("0");}
var TimeYear=Time.getFullYear();var TimeMonth=Time.getMonth()+1;if(TimeMonth.toString().length==1){TimeMonth="0"+TimeMonth;}
var TimeDate=Time.getDate();if(TimeDate.toString().length==1){TimeDate="0"+TimeDate;}
var TimeHour=Time.getHours();if(TimeHour.toString().length==1){TimeHour="0"+TimeHour;}
var TimeMinute=Time.getMinutes();if(TimeMinute.toString().length==1){TimeMinute="0"+TimeMinute;}
var TimeSecond=Time.getSeconds();if(TimeSecond.toString().length==1){TimeSecond="0"+TimeSecond;}
return TimeYear+"-"+TimeMonth+"-"+TimeDate+" "+TimeHour+":"+TimeMinute+":"+TimeSecond;}
-function toolUnixTimeNow(){var GetInputA=document.getElementById("tool-unixtime-input-a").getElementsByTagName("input")[0];var GetInputB=document.getElementById("tool-unixtime-input-b").getElementsByTagName("input")[0];var GetSettingAA=document.getElementById("unixtime-setting-aa").checked;var GetSettingAB=document.getElementById("unixtime-setting-ab").checked;var GetSettingBA=document.getElementById("unixtime-setting-ba").checked;var GetSettingBB=document.getElementById("unixtime-setting-bb").checked;GetInputA.value=toolUnixTimeGetNowA('',GetSettingAA,GetSettingAB);GetInputB.value=toolUnixTimeGetNowB('',GetSettingBA,GetSettingBB);}
-function toolUnixTimeSubmit(){var GetInputA=document.getElementById("tool-unixtime-input-a").getElementsByTagName("input")[0];var GetInputB=document.getElementById("tool-unixtime-input-b").getElementsByTagName("input")[0];var GetOutputA=document.getElementById("tool-unixtime-output-a").getElementsByTagName("input")[0];var GetOutputB=document.getElementById("tool-unixtime-output-b").getElementsByTagName("input")[0];var GetSettingAA=document.getElementById("unixtime-setting-aa").checked;var GetSettingAB=document.getElementById("unixtime-setting-ab").checked;var GetSettingBA=document.getElementById("unixtime-setting-ba").checked;var GetSettingBB=document.getElementById("unixtime-setting-bb").checked;GetOutputA.value=toolUnixTimeGetNowB(GetInputA.value,GetSettingAA,GetSettingAB);GetOutputB.value=toolUnixTimeGetNowA(GetInputB.value,GetSettingBA,GetSettingBB);}
+function toolUnixTimeNow(){var GetInputA=document.getElementById("tool-unixtime-input-a").getElementsByTagName("input")[0];var GetInputB=document.getElementById("tool-unixtime-input-b").getElementsByTagName("input")[0];var GetSettingAA=document.getElementById("unixtime-setting-aa").checked;var GetSettingAB=document.getElementById("unixtime-setting-ab").checked;var GetSettingBA=document.getElementById("unixtime-setting-ba").checked;var GetSettingBB=document.getElementById("unixtime-setting-bb").checked;if(GetSettingAA==true){var Time=new Date();var TextLength=Time.getTime().toString().length;GetInputA.value=Time.getTime().toString().substring(0,TextLength-3);}else if(GetSettingAB==true){GetInputA.value=new Date().getTime();}
+GetInputB.value=toolUnixTimeToTime(new Date().getTime(),true);}
+function toolUnixTimeSubmit(){var GetInputA=document.getElementById("tool-unixtime-input-a").getElementsByTagName("input")[0];var GetInputB=document.getElementById("tool-unixtime-input-b").getElementsByTagName("input")[0];var GetOutputA=document.getElementById("tool-unixtime-output-a").getElementsByTagName("input")[0];var GetOutputB=document.getElementById("tool-unixtime-output-b").getElementsByTagName("input")[0];var GetSettingAA=document.getElementById("unixtime-setting-aa").checked;var GetSettingAB=document.getElementById("unixtime-setting-ab").checked;var GetSettingBA=document.getElementById("unixtime-setting-ba").checked;var GetSettingBB=document.getElementById("unixtime-setting-bb").checked;if(GetSettingAA==true){GetOutputA.value=toolUnixTimeToTime(GetInputA.value,false);}else if(GetSettingAB==true){GetOutputA.value=toolUnixTimeToTime(GetInputA.value,GetSettingAB);}
+GetOutputB.value=toolUnixTimeToUnix(GetInputB.value,GetSettingBB);}
function toolUnixTimeClear(){document.getElementById("tool-unixtime-input-a").getElementsByTagName("input")[0].value='';document.getElementById("tool-unixtime-input-b").getElementsByTagName("input")[0].value='';document.getElementById("tool-unixtime-output-a").getElementsByTagName("input")[0].value='';document.getElementById("tool-unixtime-output-b").getElementsByTagName("input")[0].value='';}
function toolCalculateSubmit(){GetInput=document.getElementById("tool-calculate-input");GetToFixed=document.getElementById("tool-calculate-tofixed");GetResult=document.getElementById("tool-calculate-result").getElementsByTagName("span")[0];GetCal=GetInput.value;GetCal=GetCal.replace(/π/g,"Math.PI");GetCal=GetCal.replace(/幂/g,"Math.pow");GetCal=GetCal.replace(/平方根/g,"Math.sqrt");if(GetToFixed.value>=0&&GetToFixed.value<=16){GetResult.innerText=eval(GetCal).toFixed(GetToFixed.value);}else{GetResult.innerText="保留位数有误(0 ~ 16 之间)";}}
function toolCalculateClear(){GetInput=document.getElementById("tool-calculate-input");GetInput.value='';GetResult.innerText='';}
diff --git a/docs/tool.html b/docs/tool.html
index 8cc3e24..f5cb4e9 100644
--- a/docs/tool.html
+++ b/docs/tool.html
@@ -15,7 +15,9 @@