完成 Unix 时间戳转换工具

This commit is contained in:
2019-10-15 23:45:49 +08:00
parent 458f87afe1
commit b33dac7746
5 changed files with 134 additions and 93 deletions

View File

@@ -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;
}

View File

@@ -20,7 +20,7 @@
<div class="search-engine">
<div class="search-engine-bar">
<input id="search-engine-input" type="text" placeholder="输入关键词进行搜索" onkeydown="if (event.keyCode == 13) {searchWeb();}" />
<svg class="search-engine-submit" viewBox="0 0 24 24" onclick="searchWeb()">
<svg class="search-engine-submit" viewbox="0 0 24 24" onclick="searchWeb()">
<path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
</svg>
</div>

View File

@@ -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); // 转换为时间戳
}
// 按钮:重置 //

11
docs/js/tool.min.js vendored
View File

@@ -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='';}

View File

@@ -15,7 +15,9 @@
<header>索引</header>
<div class="tool-nav-link">
<ul>
<li><a href="index.html">主页</a></li>
<li><a href="#tool-unixtime">Unix 时间戳转换</a></li>
<li><a href="#tool-downloadtime">计算下载用时</a></li>
<li><a href="#tool-calculate">简易计算</a></li>
<li><a href="#tool-genlink">生成批量下载链接</a></li>
<li><a href="#tool-runjs">运行 JavaScript</a></li>
@@ -24,9 +26,9 @@
</div>
<!-- Unix 时间戳转换 -->
<div id="tool-unixtime">
<header>Unix 时间戳转换(未完成)</header>
<header>Unix 时间戳转换</header>
<!-- 时间戳转换为时间 -->
<p><marquee behavior="alternate" direction="right">时间戳转换为时间</marquee></p>
<p><marquee behavior="alternate" direction="right">时间戳转换为北京时间</marquee></p>
<!-- 输入框 -->
<div id="tool-unixtime-input-a">
<span>Unix 时间戳:</span><input type="text" />
@@ -45,7 +47,7 @@
</div>
<hr />
<!-- 时间转换为时间戳 -->
<p><marquee behavior="alternate" direction="right">时间转换为时间戳</marquee></p>
<p><marquee behavior="alternate" direction="right">北京时间转换为时间戳</marquee></p>
<!-- 输入框 -->
<div id="tool-unixtime-input-b">
<span>时间:</span><input type="text" />
@@ -68,6 +70,31 @@
<div class="tool-button" onclick="toolUnixTimeSubmit()">转换</div>
<div class="tool-button" onclick="toolUnixTimeClear()">重置</div>
</div>
<!-- 计算下载用时 -->
<div id="tool-downloadtime">
<header>计算下载用时(未完成)</header>
<!-- 输入 -->
<div id="tool-downloadtime-input">
<b>文件大小:</b><input type="text" /><br />
<b>下载速度:</b><input type="text" />
</div>
<!-- 结果 -->
<div id="tool-downloadtime-output">
<b>大约用时:</b><span>待计算</span>
</div>
<!-- 按钮 -->
<div class="tool-button" onclick="toolDownloadTimeSubmit()">计算</div>
<div class="tool-button" onclick="toolDownloadTimeClear()">重置</div>
<!-- 帮助 -->
<div id="tool-downloadtime-help">
<p><b>文件大小</b></p>
<p>数值 + 单位B / KB / MB / GB / TB</p>
<p>例如2 KB、5.5 GB</p>
<p><b>下载速度(每秒)</b></p>
<p>数值 + 单位B / KB / MB / GB / TB</p>
<p>例如2 KB、5.5 GB</p>
</div>
</div>
<!-- 简易计算 -->
<div id="tool-calculate">
<header>简易计算</header>