Date Object Method In TypeScript: Part 5

Before reading this article, please go through the following articles:

  1. Date Object Method In TypeScript: Part 1

  2. Date Object Method In TypeScript: Part 2

  3. Date Object Method In TypeScript: Part 3

  4. Date Object Method In TypeScript: Part 4

 

Introduction

The Date object is the key to date and time functionality in TypeScript. If we create it with no argument passed to its constructor, it will contain the date and time of the user's computer. The Date object also provides a number of functions dealing with something called Coordinated Universal Time (UTC) time, also known as Greenwich Mean Time (GMT). The World Time Standard is based on UTC time.

In this article I am describing the date object's "getUTCDate" and "getUTCDay" methods in TypeScript.

get
UTCDate() Method

In TypeScript, the getUTCDate method() is used to get the date of the month between 1 and 31 of the date object, identical to UTC.

Syntax

Date.getUTCDate()

Function

getUTCDate()

    {

        var date = new Date();

        var span = document.createElement("span");

        span.style.color = "Blue";

        span.innerText = "getUTCDate Method \n The day of the month, According to UTC-> " + date.getUTCDate() + "\n";

        document.body.appendChild(span);

    }

 

 

getUTCDay() Method

In TypeScript, The getUTCDay method() is used to get the day of the week of a specified date or the current date, identical to UTC. The returned value is an integer representing the day of the week, such as 0 for Sunday, 1 for Monday, and so on.

Syntax

Date.getUTCDay()


F
unction

 

    getUTCDay()

    {

        var Wday: string[] = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

        var day = new Date();

        var TodayDay = Wday[day.getUTCDay()];

        var span = document.createElement("span");

        span.style.color = "green";

        span.innerText = "getUTCDay Method \n The day of the week, According to UTC-> " + TodayDay + "\n";

        document.body.appendChild(span);

    }

 

Complete Program

getUTCDate_getUTCDay.ts

class getUTCDate_getUTCDay

{

    getUTCDate()

    {

        var date = new Date();

        var span = document.createElement("span");

        span.style.color = "Blue";

        span.innerText = "getUTCDate Method \n The day of the month, According to UTC-> " + date.getUTCDate() + "\n";

        document.body.appendChild(span);

    }

    getUTCDay()

    {

        var Wday: string[] = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

        var day = new Date();

        var TodayDay = Wday[day.getUTCDay()];

        var span = document.createElement("span");

        span.style.color = "green";

        span.innerText = "getUTCDay Method \n The day of the week, According to UTC-> " + TodayDay + "\n";

        document.body.appendChild(span);

    }

}

window.onload = () =>

{

    var obj = new getUTCDate_getUTCDay();

    obj.getUTCDate();

    obj.getUTCDay();

};

 

getUTCDate_getUTCDay_MethodDemo.htm

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">

<head>

    <meta charset="utf-8" />

    <title>TypeScript HTML App</title>

    <link rel="stylesheet" href="app.css" type="text/css" />

    <script src="getUTCDate_getUTCDay.js"></script>

</head>

<body>

    <h3>getUTCDate and getUTCDay method in TypeScript</h3>

    <div id="content"></div>

</body>

</html>

 

getUTCDate_getUTCDay.js

var getUTCDate_getUTCDay = (function () {

    function getUTCDate_getUTCDay() { }

    getUTCDate_getUTCDay.prototype.getUTCDate = function () {

        var date = new Date();

        var span = document.createElement("span");

        span.style.color = "Blue";

        span.innerText = "getUTCDate Method \n The day of the month, According to UTC-> " + date.getUTCDate() + "\n";

        document.body.appendChild(span);

    };

    getUTCDate_getUTCDay.prototype.getUTCDay = function () {

        var Wday = [

            "Sunday",

            "Monday",

            "Tuesday",

            "Wednesday",

            "Thursday",

            "Friday",

            "Saturday"

        ];

        var day = new Date();

        var TodayDay = Wday[day.getUTCDay()];

        var span = document.createElement("span");

        span.style.color = "green";

        span.innerText = "getUTCDay Method \n The day of the week, According to UTC-> " + TodayDay + "\n";

        document.body.appendChild(span);

    };

    return getUTCDate_getUTCDay;

})();

window.onload = function () {

    var obj = new getUTCDate_getUTCDay();

    obj.getUTCDate();

    obj.getUTCDay();

};

//@ sourceMappingURL=getUTCDate_getUTCDay.js.map

 

Output


result.jpg

Up Next
    Ebook Download
    View all

    Test

    Read by 16 people
    Download Now!
    Learn
    View all