JavaScript gets the current datetime at the same time as the day of the week, specific code is as follows:
- <html>
- <head>
- <Meta http-equiv= "content-type" content= "text/html; Charset=utf-8 " />
- <script type="Text/javascript" src= "https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/ Jquery.min.js "></script>
- <script type="Text/javascript">
- function CurrentTime () {
- var d=New Date (),str=";
- Str+=d.getfullyear () + ' year ';
- Str+=d.getmonth () + 1+ ' month ';
- Str+=d.getdate () + ' Day ';
- Str+=d.gethours () + ' time ';
- Str+=d.getminutes () + ' min ';
- str+= d.getseconds () + ' second ';
- return str;
- }
- SetInterval (function () {$ (' #time '). HTML (currenttime)},1000);
- </Script>
- </head>
- <body>
- <div id="Time"></div>
- </body>
- </html>
Dynamically display the current datetime on the Web page and show the practice of the week:
function ShowTime () {
var show_day = new Array (' Monday ', ' Tuesday ', ' Wednesday ', ' Thursday ', ' Friday ', ' Saturday ', ' Sunday ');
var time = new Date ();
var year = Time.getfullyear ();
var month = Time.getmonth () + 1;
var date = Time.getdate ();
var day = Time.getday ();
var hour = time.gethours ();
var minutes = time.getminutes ();
var second = Time.getseconds ();
Month < 10? month = ' 0 ' + month:month;
Month = month + 1;
alert (year);
Hour < 10? hour = ' 0 ' + hour:hour;
Minutes < 10? minutes = ' 0 ' + minutes:minutes;
Second < 10? Second = ' 0 ' + second:second;
var now_time = year + ' years ' + month + ' month ' + date + ' Day ' + ' + show_day[day-1] + ' + hour + ': ' + minutes + ': ' + second ;
document.getElementById (' Lishow '). InnerHTML = Now_time;
SetTimeout ("ShowTime ();", 1000);
}
SetInterval ("ShowTime ();", 1000);
JS Get current date time display week