JavaScript Time Object Practice _ Time Date

Source: Internet
Author: User
Tags current time getdate time and date time in milliseconds
The Date object provides three methods:
1. Obtain the current time and date from the system;
2. Set the time and date;
3. Time, date converted into other formats.

Setyear Set the current year
Setmonth Set the current month
Setdate Set the current date
Setday sets the number of weeks for the current object
Sethours set the current hour
Setminutes set the current minute
Setseconds Set the current second
SetTime set current time in milliseconds
<textarea id="runcode20409"><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/> <title> built-in to ext--date</title> </pead> <body> <script language=" JavaScript ">//Get current date from system var now=new date (); document.write ("is Now" +now.getyear () + "year" + (Now.getmonth () +1) + "month" +now.getdate () + "Day" +now.gethours () + "time" + Now.getminutes () + "Min" +now.getseconds () + "seconds" + "");/month is calculated from 0 to 11, so +1. Set Date var now=new date (); Now.setyear (1986); Now.setmonth (10); Now.setdate (06); document.write ("Birth date is" +now.getyear () + "year" + (Now.getmonth () +1) + "month" +now.getdate () + "Day" + ""); Convert date format var now=new date (); document.write (now.togmtstring () + "")//Convert to GMT Format date document.write (now.tolocalestring () + ""),//Convert cost format date </ script> </body> </ptml></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Show Current Date:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/> <title> show Current time </title> </pead> <body> <script language=" JavaScript "& Gt var objdate=new Date (); The Var year=objdate.getfullyear ()///definition displays a four-digit number of years. The Var month=objdate.getmonth () +1;//month is calculated from 0, so add one. var date=objdate.getdate (); var day=objdate.getday (); var hours=objdate.gethours (); var minutes=objdate.getminutes (); var seconds=objdate.getseconds (); Switch (day) {case 0:day= "Sunday"; Break Case 1:day= "Monday"; Break Case 2:day= "Tuesday"; Break Case 3:day= "Wednesday"; Break Case 4:day= "Thursday"; Break Case 5:day= "Friday"; Break Case 6:day= "Saturday"; Break document.write ("Today is" +year+ "year" +month+ "month" +date+ "Day" + "," +hours+ ":" +minutes+ ":" +seconds+ "," +day+ ""); </script> </body>;/html>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.