Date Object Method In TypeScript: Part 6

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

  5. Date Object Method In TypeScript: Part 5

 

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), also known as Greenwich Mean Time (GMT) during winter. The World Time Standard is set by the UTC time.

In this article I am describing the date object's "getUTCFullYear" and "getUTCMonth" method in the TypeScript.

get
UTCFullYear() Method

In TypeScript,
the getUTCFullYear method returns the year of the specified date or the current date, identical to UTC. The getUTCFullYear method() will be returned as an absolute value.

Syntax

Date.getUTCFullYear()

Function

getUTCFullYear()

    {

        var year = new Date();

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

        span.innerText = "getUTCFullYear Method \n Current year, According to UTC-> " + year.getUTCFullYear() + "\n";

        document.body.appendChild(span);

    }

 

 

getUTCMonth() Method

In TypeScript, the getUTCMonth method returns the month for the specified date or current the date, identical to UTC. The months are numbered starting with zero. January is 0 and December is 11.

Syntax

Date.getUTCMonth()


F
unction

 

   

getUTCMonth()

    {

        var CurrntMonth: string[] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", ];

        var month = new Date();

        var CrrntUTCMonth = CurrntMonth[month.getUTCMonth()];

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

        span.style.color = "Blue";

        span.innerText = "getUTCMonth Method \n Current Month name, According to UTC-> " + CrrntUTCMonth + "\n";

        document.body.appendChild(span);

    }

 

Complete Program

getUTCFullYear_getUTCMonth.ts

class getUTCFullYear_getUTCMonth

{

    getUTCFullYear()

    {

        var year = new Date();

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

        span.innerText = "getUTCFullYear Method \n Current year, According to UTC-> " + year.getUTCFullYear() + "\n";

        document.body.appendChild(span);

    }

    getUTCMonth()

    {

        var CurrntMonth: string[] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", ];

        var month = new Date();

        var CrrntUTCMonth = CurrntMonth[month.getUTCMonth()];

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

        span.style.color = "Blue";

        span.innerText = "getUTCMonth Method \n Current Month name, According to UTC-> " + CrrntUTCMonth + "\n";

        document.body.appendChild(span);

    }

}

window.onload = () =>

{

    var obj = new getUTCFullYear_getUTCMonth();

    obj.getUTCFullYear();

    obj.getUTCMonth();

};

 

getUTCFullYear_getUTCMonth_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="getUTCFullYear_getUTCMonth.js"></script>

</head>

<body>

    <h3>getUTCFullYear and getUTCMonth method in TypeScript</h3>

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

</body>

</html>

 

getUTCFullYear_getUTCMonth.js

var getUTCFullYear_getUTCMonth = (function () {

    function getUTCFullYear_getUTCMonth() { }

    getUTCFullYear_getUTCMonth.prototype.getUTCFullYear = function () {

        var year = new Date();

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

        span.innerText = "getUTCFullYear Method \n Current year, According to UTC-> " + year.getUTCFullYear() + "\n";

        document.body.appendChild(span);

    };

    getUTCFullYear_getUTCMonth.prototype.getUTCMonth = function () {

        var CurrntMonth = [

            "January",

            "February",

            "March",

            "April",

            "May",

            "June",

            "July",

            "August",

            "September",

            "October",

            "November",

            "December",

           

        ];

        var month = new Date();

        var CrrntUTCMonth = CurrntMonth[month.getUTCMonth()];

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

        span.style.color = "Blue";

        span.innerText = "getUTCMonth Method \n Current Month name, According to UTC-> " + CrrntUTCMonth + "\n";

        document.body.appendChild(span);

    };

    return getUTCFullYear_getUTCMonth;

})();

window.onload = function () {

    var obj = new getUTCFullYear_getUTCMonth();

    obj.getUTCFullYear();

    obj.getUTCMonth();

};

//@ sourceMappingURL=getUTCFullYear_getUTCMonth.js.map

 

Output


Result.jpg

Up Next
    Ebook Download
    View all

    Test

    Read by 16 people
    Download Now!
    Learn
    View all