Date Object Method In TypeScript: Part 4

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

 

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 (in the Winter) as Greenwich Mean Time (GMT).

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

getTime() Method

In TypeScript,
the getTime() method is used to return the number of milliseconds or integer value of the specified date and time. The returned value is between midnight of January 1, 1970 and the specified date.

Syntax

Date.getTime()

Function

    getTime()

    {

        var time = new Date();

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

        span.style.color = "Blue";

        span.innerText = "getTime Method \n Display the number of milliseconds since midnight, January 1, 1970-> " + time.getTime() + "\n";

        document.body.appendChild(span);

    }

 

 

getMinutes() Method

In TypeScript, the getMinutes() method is used to get the minutes of the local time in the specified date or current date and time. The getMinutes method returns an integer value between 0 and 59.

Syntax

Date.getminutes()


F
unction

 

getMinutes()

    {

        var minutes = new Date();

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

        span.innerText = "getMinutes Method \n The Minutes of the time right now-> " + minutes.getMinutes() + "\n";

        document.body.appendChild(span);

    }

 

Complete Program

getTime_getMinutes.ts

class getTime_getMinutes

{

    getTime()

    {

        var time = new Date();

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

        span.style.color = "Blue";

        span.innerText = "getTime Method \n Display the number of milliseconds since midnight, January 1, 1970-> " + time.getTime() + "\n";

        document.body.appendChild(span);

    }

    getMinutes()

    {

        var minutes = new Date();

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

        span.innerText = "getMinutes Method \n The Minutes of the time right now-> " + minutes.getMinutes() + "\n";

        document.body.appendChild(span);

    }

}

window.onload = () =>

{

    var obj = new getTime_getMinutes();

    obj.getMinutes();

    obj.getTime();

};

 

getTime_getMinutes_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="getTime_getMinutes.js"></script>

</head>

<body>

    <h3>getTime and getMinutes method in TypeScript</h3>

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

</body>

</html>

 

getTime_getMinutes.js

var getTime_getMinutes = (function () {

    function getTime_getMinutes() { }

    getTime_getMinutes.prototype.getTime = function () {

        var time = new Date();

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

        span.style.color = "Blue";

        span.innerText = "getTime Method \n Display the number of milliseconds since midnight, January 1, 1970-> " + time.getTime() + "\n";

        document.body.appendChild(span);

    };

    getTime_getMinutes.prototype.getMinutes = function () {

        var minutes = new Date();

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

        span.innerText = "getMinutes Method \n The Minutes of the time right now-> " + minutes.getMinutes() + "\n";

        document.body.appendChild(span);

    };

    return getTime_getMinutes;

})();

window.onload = function () {

    var obj = new getTime_getMinutes();

    obj.getMinutes();

    obj.getTime();

};

//@ sourceMappingURL=getTime_getMinutes.js.map

  

Output


result.jpg

Up Next
    Ebook Download
    View all

    Test

    Read by 16 people
    Download Now!
    Learn
    View all