基本上,我试图让用户以mm / dd / yyyy的形式输入日期。它可以是任何日期,但必须选择它。我想要做的是计算自输入日期以来经过的年数,月数和天数。我已经达到了可以选择日期的程度,但除此之外,我很难过。这就是我所拥有的:
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">
<Title>Elapsed Time Calculator</Title>
<script src="modernizr.custom.05819.js"></script><!--Links to file containing modernizer library-->
<body>
<!-- Navigation -->
<nav>
<ul class="w3-navbar w3-black">
<li><a href="file:///C:/Users/Kyle/Desktop/Document1.html">Home</a></li> <!--Link to Home Page-->
<li><a href="file:///C:/Users/Kyle/Desktop/Document2.html">NHL Teams</a></li><!--Link to Page of NHL Teams-->
<li><a href="file:///C:/Users/Kyle/Desktop/Document3.html">AHL Teams</a></li><!--Link to Page of AHL Teams-->
<li><a href="file:///C:/Users/Kyle/Desktop/Document4.html">WHL Teams</a></li><!--Link to Page of WHL Teams-->
<li><a href="file:///C:/Users/Kyle/Desktop/Document5.html">G.A.A. Calculator</a></li><!--Link to Page of WHL Teams-->
<li><a href="file:///C:/Users/Kyle/Desktop/Document6.html">Fan Survey</a></li><!--Link to Fan Survey Page-->
<li><a href="file:///C:/Users/Kyle/Desktop/Document7.html">Web Safety</a></li><!--Link to Page about Web Safety-->
<li><a href="file:///C:/Users/Kyle/Desktop/Document8.html">Elapsed Time</a></li><!--Link to Page That Calculates Elapsed Time Between Two Dates-->
</ul>
</nav>
<header>
<h1 style="text-align:center;">Elapsed Time</h1>
</header>
<article>
<form>
<fieldset>
<label for="dateSelected">
Select a date
</label>
<input type="date" id="dateSelected" />
</fieldset>
<label for "timeElapsed"> Time Elapsed: </label>
</form>
</article>
</body>
</html>
如果我没记错的话,你的方式是将日期转换为毫秒,并从该数字转换,但我不太确定如何做到这一点用户输入的数据。有人可以帮忙吗?
答案 0 :(得分:0)
使用此处所述方法http://www.w3schools.com/js/js_dates.asp创建新日期,然后使用此问题中的代码Calculate time difference between two times javascript