公众号

js距离现在时间计算

js距离现在时间计算,如题js文件代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<script language="javascript">
var biryear = 2015;
var birmonth = 12;
var birday = 11;
var year = new Date();
var getyear = year.getYear();
TMonth = new Array('Jan','Feb','Mar','Apr','May','June','July','Aug','Sep','Oct','Nov','Dec');
nowMonth = birmonth - 1;
bmonth = TMonth[nowMonth];
var timerid;
var timerRunning = false;
var today = new Date();
var startday = new Date();
var enday = new Date();
var minPerDay = 0;
var secsLeft = 0;
var secsRound = 0;
var secsRemain = 0;
var minLeft = 0;
var minRound = 0;
var minRemain = 0;
var timeRemain = 0;
function showtime()
{
startday = new Date(""+bmonth+" "+birday+", "+biryear+" 00:00 EDT");
startday.setYear(""+biryear+"");
today = new Date();
secsPerDay = 1000 ;
minPerDay = 60 * 1000 ;
hoursPerDay = 60 * 60 * 1000;
PerDay = 24 * 60 * 60 * 1000;
secsLeft = (today.getTime() - startday.getTime()) / minPerDay;
secsRound = Math.round(secsLeft);
secsRemain = secsLeft - secsRound;
secsRemain = (secsRemain < 0) ? secsRemain = 60 - ((secsRound - secsLeft) * 60) : secsRemain = (secsLeft - secsRound) * 60;
secsRemain = Math.round(secsRemain);
minLeft = ((today.getTime() - startday.getTime()) / hoursPerDay);
minRound = Math.round(minLeft);
minRemain = minLeft - minRound;
minRemain = (minRemain < 0) ? minRemain = 60 - ((minRound - minLeft) * 60) : minRemain = ((minLeft - minRound) * 60);
minRemain = Math.round(minRemain - 0.495);
hoursLeft = ((today.getTime() - startday.getTime()) / PerDay);
hoursRound = Math.round(hoursLeft);
hoursRemain = hoursLeft - hoursRound;
hoursRemain = (hoursRemain < 0) ? hoursRemain = ((hoursLeft - hoursRound) * 24 +12) : hoursRemain = 12 - ((hoursRound - hoursLeft) * 24);
hoursRemain = Math.round(hoursRemain - 0.5);
daysLeft = ((today.getTime() - startday.getTime()) / PerDay);
daysLeft = (daysLeft + 0.5);
daysRound = Math.round(daysLeft);
daysRemain = daysRound;
day_rem = " 天 "
hour_rem = " 小时 "
min_rem = " 分 "
sec_rem = " 秒 "
timeRemain =daysRemain + day_rem + hoursRemain + hour_rem + minRemain + min_rem + secsRemain + sec_rem;
document.up.face.value = timeRemain;
timerid = setTimeout("showtime()",1000);
timerRunning = true;
}
</script>

在html文件中

1
2
3
4
<FORM name=up onsubmit=1 align="center">
<INPUT class="forever" value="计算出您的精彩人生!" name= "face" readonly onfocus="this.blur()" align="center">
</FORM>

input标签css样式

1
.forever {background-color:transparent;width:1000px;height:80px;text-align:center;font-size:80px;font-family:"微软雅黑";border-left: 0;border-top: 0;border-right: 0;border-bottom: 0;}

最后想说:Fork me on GitHub 欢迎 Star

  • 本文作者:Hunter-Zack
  • 本文链接: 2017/09/js+time/
  • 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 CN 许可协议。转载请注明出处!
🙈坚持原创技术分享,您的支持将鼓励我继续创作🙈