Multidimensional Arrays

 

Multidimensional Arrays

 

The array examples I have shown so far deal with single-dimensional arrays. That is, there is a single value associated with each index of the array. Some languages allow you to create multi-dimensional array as a database table with multiple fields (Coloumns).

Javascript does not provide explicit support for multi-dimesional arrays, but you can simulate them by creating an array of custom objects.

 

Date Object

 

The Date Object is the means by which you work with date and time values in javascript. You should understand three significant facts regarding the Date object before using it:

 

] Following the UNIX convention, Javascript considers January 1,1970 to be the baseline date. Consequently , you cannot work with dates prior to that time frame.

] When you create a Date Object , the time reflected within the object is based on the client machine. You are thus dependent on the client computer to have a working and accurate clock. Keep this dependency in mind as you consider time-sensitive code in your Javascript scripts.

 

Creating a Date Object

 

Creating a Date object is similar to creating string or array objects. You can create as many Date objects as you want in your scripts. Using the new operator, you can define a Date Object as follows:

 

Var dateVariable=new Date([parameter])

 

You can include several parameters.

 

Method

Description

getDate()

Returns date within month(1-31)

getDay()

Returns day within week(0-6)

getHours()

Returns hour within day(0-23)

getMinutes()

Returns minutes within hour(0-59)

getSeconds()

Returns seconds within minutes

getTime()

Returns number of milliseconds

getYear()

Returns number of years since 1900

getTimeZoneOffset()

Returns minutes offset from GMT/UTC

getMonth()

Returns month within year

 

Example

 

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Date object</title>

</head>

<body style="background-color: aquamarine;">

    <h1>Date object</h1>

    <hr>

<script>

document.write("<b>");

    dt=new Date();

    document.write(dt);

    document.write("<br/>");

    document.write("<br/>");

    document.write("Date within month:"+dt.getDate());

    document.write("<br/>");

    document.write("<br/>");

    document.write("Day within week:"+dt.getDay());

    document.write("<br/>");

    document.write("<br/>");

    document.write("Month within year:"+dt.getMonth());

    document.write("<br/>");

    document.write("<br/>");

    document.write("Number of year since 1900:"+dt.getYear());

    document.write("<br/>");

    document.write("<br/>");

    document.write("Hour within day:"+dt.getHours());

    document.write("<br/>");

    document.write("<br/>");

    document.write("Minutes within hour:"+dt.getMinutes());

    document.write("<br/>");

    document.write("<br/>");

    document.write("Seconds within minutes :"+dt.getSeconds());

    document.write("<br/>");

    document.write("Number of milliseconds since 1/1/70:"+dt.getTime());

    document.write("<br/>");

    document.write("<br/>");

</script>

 

</hr>

</body>

</html>

 

Output


 

Set methods of the Date object

Method

Description

setDate()

Returns date within month(1-31)

setDay()

Returns day within week(0-6)

setHours()

Returns hour within day(0-23)

setMinutes()

Returns minutes within hour(0-59)

setSeconds()

Returns seconds within minutes

setTime()

Returns number of milliseconds

setYear()

Returns number of years since 1900

setTimeZoneOffset()

Returns minutes offset from GMT/UTC

setMonth()

Returns month within year

 

Example

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Date Object</title>

</head>

<body style="background-color: tomato;">

    <h1>Set Methos</h1>

    <hr>

    <script>

        document.write("<b>");

            dt=new Date();

            document.write(dt);

            dt.setDate(29);

            dt.setHours(20);

            dt.setMinutes(30);

            dt.setMonth(11);

            dt.setSeconds(50);

            dt.setYear(2001);

            document.write("<br/>");

            document.write(dt);

            document.write("</b>");  

    </script>

    </hr>

</body>

</html>

 

Output



No comments:

Post a Comment