Date Object Method In TypeScript: Part 6

Date Object Method In TypeScript: Part 6 

 
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), 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.
 

getUTCFullYear() 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
  1. Date.getUTCFullYear()  
Function
  1. getUTCFullYear() {  
  2.  var year = new Date();  
  3.  var span = document.createElement("span");  
  4.  span.innerText = "getUTCFullYear Method \n Current year, According to UTC-> " + year.getUTCFullYear() + "\n";  
  5.  document.body.appendChild(span);  
  6. }  

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
  1. Date.getUTCMonth()  
Function
  1. getUTCMonth() {  
  2.  var CurrntMonth: string[] = ["January""February""March""April""May""June""July""August""September""October""November""December", ];  
  3.  var month = new Date();  
  4.  var CrrntUTCMonth = CurrntMonth[month.getUTCMonth()];  
  5.  var span = document.createElement("span");  
  6.  span.style.color = "Blue";  
  7.  span.innerText = "getUTCMonth Method \n Current Month name, According to UTC-> " + CrrntUTCMonth + "\n";  
  8.  document.body.appendChild(span);  
  9. }  

Complete Program

 
getUTCFullYear_getUTCMonth.ts
  1. class getUTCFullYear_getUTCMonth {  
  2.  getUTCFullYear() {  
  3.   var year = new Date();  
  4.   var span = document.createElement("span");  
  5.   span.innerText = "getUTCFullYear Method \n Current year, According to UTC-> " + year.getUTCFullYear() + "\n";  
  6.   document.body.appendChild(span);  
  7.  }  
  8.  getUTCMonth() {  
  9.   var CurrntMonth: string[] = ["January""February""March""April""May""June""July""August""September""October""November""December", ];  
  10.   var month = new Date();  
  11.   var CrrntUTCMonth = CurrntMonth[month.getUTCMonth()];  
  12.   var span = document.createElement("span");  
  13.   span.style.color = "Blue";  
  14.   span.innerText = "getUTCMonth Method \n Current Month name, According to UTC-> " + CrrntUTCMonth + "\n";  
  15.   document.body.appendChild(span);  
  16.  }  
  17. }  
  18. window.onload = () => {  
  19.  var obj = new getUTCFullYear_getUTCMonth();  
  20.  obj.getUTCFullYear();  
  21.  obj.getUTCMonth();  
  22. }; 
getUTCFullYear_getUTCMonth_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="getUTCFullYear_getUTCMonth.js"></script>  
  9.     </head>  
  10.     <body>  
  11.         <h3>getUTCFullYear and getUTCMonth method in TypeScript</h3>  
  12.         <div id="content"></div>  
  13.     </body>  
  14. </html>  
getUTCFullYear_getUTCMonth.js
  1. var getUTCFullYear_getUTCMonth = (function() {  
  2.  function getUTCFullYear_getUTCMonth() {}  
  3.  getUTCFullYear_getUTCMonth.prototype.getUTCFullYear = function() {  
  4.   var year = new Date();  
  5.   var span = document.createElement("span");  
  6.   span.innerText = "getUTCFullYear Method \n Current year, According to UTC-> " + year.getUTCFullYear() + "\n";  
  7.   document.body.appendChild(span);  
  8.  };  
  9.  getUTCFullYear_getUTCMonth.prototype.getUTCMonth = function() {  
  10.   var CurrntMonth = ["January""February""March""April""May""June""July""August""September""October""November""December", ];  
  11.   var month = new Date();  
  12.   var CrrntUTCMonth = CurrntMonth[month.getUTCMonth()];  
  13.   var span = document.createElement("span");  
  14.   span.style.color = "Blue";  
  15.   span.innerText = "getUTCMonth Method \n Current Month name, According to UTC-> " + CrrntUTCMonth + "\n";  
  16.   document.body.appendChild(span);  
  17.  };  
  18.  return getUTCFullYear_getUTCMonth;  
  19. })();  
  20. window.onload = function() {  
  21.  var obj = new getUTCFullYear_getUTCMonth();  
  22.  obj.getUTCFullYear();  
  23.  obj.getUTCMonth();  
  24. };  
Output
 
Result.jpg 


Similar Articles