Javascript to get the current date and time
Sometimes there may be such a requirement, so that you can view the date by time. I used to steal all my handwriting. I wrote it myself when I was bored today, which is quite simple. The time is calculated every second. Demo
The following is the Html code:
<! DOCTYPE html>
<Html class = "no-js">
<Head>
<Meta charset = "UTF-8">
<Title> current time </title>
<Script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type = "text/javascript"> </script>
<Style type = "text/css">
. Date {height: 100px; line-height: 100px; margin: 0 auto; font-family: Arial, Helvetica, sans-serif; font-size: 40px;
Border: solid 1px # ccc; box-shadow: 0 0 3px rgba (0,0, 0, 0.3) inset; border-radius: 5px; text-shadow: 1px 1px 2px rgba (0.3, 0 );}
. Date strong {padding: 0 10px; display: inline-block; height: 100px; border-right: solid 1px # ccc ;}
</Style>
</Head>
<Body>
<H1> js simply obtains the current date and time <P class = "date">
<Strong id = "Y"> </strong>
<Strong id = "MH"> </strong>
<Strong id = "TD"> </strong>
<Strong id = "D"> </strong>
<Strong id = "H"> </strong>
<Strong id = "M"> </strong>
<Strong id = "S"> </strong>
</P>
<Script type = "text/javascript">
$ (Document). ready (function (){
SetInterval (showTime, 1000 );
Function timer (obj, txt ){
Obj. text (txt );
}
Function showTime (){
Var today = new Date ();
Var weekday = new Array (7)
Weekday [0] = "Monday"
Weekday [1] = "Tuesday"
Weekday [2] = "weekday"
Weekday [3] = "Thursday"
Weekday [4] = "Friday"
Weekday [5] = "Saturday"
Weekday [6] = "Sunday"
Var y = today. getFullYear () + "year ";
Var month = today. getMonth () + "month ";
Var td = today. getDate () + "day ";
Var d = weekday [today. getDay ()];
Var h = today. getHours ();
Var m = today. getMinutes ();
Var s = today. getSeconds ();
Timer ($ ("# Y"), y );
Timer ($ ("# MH"), month );
Timer ($ ("# TD"), td );
Timer ($ ("# D"), d );
Timer ($ ("# H"), h );
Timer ($ ("# M"), m );
Timer ($ ("# S"), s );
}
})
</Script>
</Body>
</Html>