Date Object Method In TypeScript: Part 4

Date Object Method In TypeScript: Part 4 

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

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
  1. Date.getTime()   
Function
  1. getTime() {  
  2.  var time = new Date();  
  3.  var span = document.createElement("span");  
  4.  span.style.color = "Blue";  
  5.  span.innerText = "getTime Method \n Display the number of milliseconds since midnight, January 1, 1970-> " + time.getTime() + "\n";  
  6.  document.body.appendChild(span);  
  7. }  

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
  1. Date.getminutes()  
Function
  1. getMinutes() {  
  2.  var minutes = new Date();  
  3.  var span = document.createElement("span");  
  4.  span.innerText = "getMinutes Method \n The Minutes of the time right now-> " + minutes.getMinutes() + "\n";  
  5.  document.body.appendChild(span);  
  6. }  

Complete Program

 
getTime_getMinutes.ts
  1. class getTime_getMinutes {  
  2.  getTime() {  
  3.   var time = new Date();  
  4.   var span = document.createElement("span");  
  5.   span.style.color = "Blue";  
  6.   span.innerText = "getTime Method \n Display the number of milliseconds since midnight, January 1, 1970-> " + time.getTime() + "\n";  
  7.   document.body.appendChild(span);  
  8.  }  
  9.  getMinutes() {  
  10.   var minutes = new Date();  
  11.   var span = document.createElement("span");  
  12.   span.innerText = "getMinutes Method \n The Minutes of the time right now-> " + minutes.getMinutes() + "\n";  
  13.   document.body.appendChild(span);  
  14.  }  
  15. }  
  16. window.onload = () => {  
  17.  var obj = new getTime_getMinutes();  
  18.  obj.getMinutes();  
  19.  obj.getTime();  
  20. };  
getTime_getMinutes_MethodDemo.htm
  1. <!DOCTYPE html>  
  2. <html lang="en"  
  3.     xmlns="http://www.w3.org/1999/xhtml">  
  4.     <head>  
  5.         <meta charset="utf-8" />  
  6.         <title>TypeScript HTML App</title>  
  7.         <link rel="stylesheet" href="app.css" type="text/css" />  
  8.         <script src="getTime_getMinutes.js"></script>  
  9.     </head>  
  10.     <body>  
  11.         <h3>getTime and getMinutes method in TypeScript</h3>  
  12.         <div id="content"></div>  
  13.     </body>  
  14. </html>  
getTime_getMinutes.js
  1. var getTime_getMinutes = (function() {  
  2.  function getTime_getMinutes() {}  
  3.  getTime_getMinutes.prototype.getTime = function() {  
  4.   var time = new Date();  
  5.   var span = document.createElement("span");  
  6.   span.style.color = "Blue";  
  7.   span.innerText = "getTime Method \n Display the number of milliseconds since midnight, January 1, 1970-> " + time.getTime() + "\n";  
  8.   document.body.appendChild(span);  
  9.  };  
  10.  getTime_getMinutes.prototype.getMinutes = function() {  
  11.   var minutes = new Date();  
  12.   var span = document.createElement("span");  
  13.   span.innerText = "getMinutes Method \n The Minutes of the time right now-> " + minutes.getMinutes() + "\n";  
  14.   document.body.appendChild(span);  
  15.  };  
  16.  return getTime_getMinutes;  
  17. })();  
  18. window.onload = function() {  
  19.  var obj = new getTime_getMinutes();  
  20.  obj.getMinutes();  
  21.  obj.getTime();  
  22. };  
Output
 
result.jpg


Similar Articles