JS (iii) Date object and Array object

Source: Internet
Author: User
Tags time zones

First, Introduction

1. Date object: The Date object, which can be used to obtain information such as dates, times, weeks, time zones, etc.

2. Array object: That is, the array object, that is, the PHP arrays in JS in the form of JS to create.

Second, the example code

/** * Date: Includes date, time, week, time zone, etc. */function myFunction () {//Date document.write (date () + "<br/>");//Standard timestamp document.write (new Date (). GetTime () + "<br/>");//1970.01.01-present time the number of milliseconds var d = new Date ();d. setFullYear (1980, N);d Ocument.write (D + ") <br/>);//Displays the 1981-12-18 standard timestamp document.write (new Date (). toUTCString () + "<br/>");// Converts a date to a string document.write (new Date (). GetDay () + "<br/>");//Get the day, minute, second}/** * week = + convert * Array Object */function MyFunction2 () {/*var weekday = new Array (7); weekday[0] = "Sunday"; weekday[1] = "Monday"; weekday[2] = "Tuesday"; weekday[3] = "Wednesday"; EKDAY[4] = "Thursday"; weekday[5] = "Friday"; weekday[6] = "Saturday"; */var weekday=new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", " Saturday ");//The above 2 kinds of JS definition array objects can be var x = new Date (). GetDay ();//Friday =>5document.write (" Today is "+ weekday[x]);//convert number to Custom week}/ * * time = alarm */function myFunction3 () {var d = new Date (), var h = d.gethours (); var m = D.getminutes (); var s = D.getsecon DS (); h = checktime (h); m = Checktime (m); s = checktime (s);d Ocument.geteleMentbyid ("Div1"). innerhtml=h+ ":" + M + ":" +s;settimeout ("MyFunction3 ()", 1000);//1 seconds to refresh once, here the method name must be in single or double quotation marks function Checktime (x) {if (x<10) {x = "0" + x;} return x;}}


JS (iii) Date object and Array object

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.