Date Object Method In TypeScript: Part 5

Date Object Method In TypeScript: Part 5 

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

getUTCDate() 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
  1. Date.getUTCDate()   
Function
  1. getUTCDate() {  
  2.  var date = new Date();  
  3.  var span = document.createElement("span");  
  4.  span.style.color = "Blue";  
  5.  span.innerText = "getUTCDate Method \n The day of the month, According to UTC-> " + date.getUTCDate() + "\n";  
  6.  document.body.appendChild(span);  
  7. }  

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
  1. Date.getUTCDay()  
Function
  1. getUTCDay() {  
  2.  var Wday: string[] = ["Sunday""Monday""Tuesday""Wednesday""Thursday""Friday""Saturday"];  
  3.  var day = new Date();  
  4.  var TodayDay = Wday[day.getUTCDay()];  
  5.  var span = document.createElement("span");  
  6.  span.style.color = "green";  
  7.  span.innerText = "getUTCDay Method \n The day of the week, According to UTC-> " + TodayDay + "\n";  
  8.  document.body.appendChild(span);  
  9. }  

Complete Program

 
getUTCDate_getUTCDay.ts
  1. class getUTCDate_getUTCDay {  
  2.   getUTCDate() {  
  3.     var date = new Date();  
  4.     var span = document.createElement("span");  
  5.     span.style.color = "Blue";  
  6.     span.innerText = "getUTCDate Method \n The day of the month, According to UTC-> " + date.getUTCDate() + "\n";  
  7.     document.body.appendChild(span);  
  8.   }  
  9.   getUTCDay() {  
  10.     var Wday: string[] = ["Sunday""Monday""Tuesday""Wednesday""Thursday""Friday""Saturday"];  
  11.     var day = new Date();  
  12.     var TodayDay = Wday[day.getUTCDay()];  
  13.     var span = document.createElement("span");  
  14.     span.style.color = "green";  
  15.     span.innerText = "getUTCDay Method \n The day of the week, According to UTC-> " + TodayDay + "\n";  
  16.     document.body.appendChild(span);  
  17.   }  
  18. }  
  19. window.onload = () => {  
  20.   var obj = new getUTCDate_getUTCDay();  
  21.   obj.getUTCDate();  
  22.   obj.getUTCDay();  
  23. };   
getUTCDate_getUTCDay_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="getUTCDate_getUTCDay.js"></script>  
  9.     </head>  
  10.     <body>  
  11.         <h3>getUTCDate and getUTCDay method in TypeScript</h3>  
  12.         <div id="content"></div>  
  13.     </body>  
  14. </html>  
getUTCDate_getUTCDay.js
  1. var getUTCDate_getUTCDay = (function() {  
  2.  function getUTCDate_getUTCDay() {}  
  3.  getUTCDate_getUTCDay.prototype.getUTCDate = function() {  
  4.   var date = new Date();  
  5.   var span = document.createElement("span");  
  6.   span.style.color = "Blue";  
  7.   span.innerText = "getUTCDate Method \n The day of the month, According to UTC-> " + date.getUTCDate() + "\n";  
  8.   document.body.appendChild(span);  
  9.  };  
  10.  getUTCDate_getUTCDay.prototype.getUTCDay = function() {  
  11.   var Wday = ["Sunday""Monday""Tuesday""Wednesday""Thursday""Friday""Saturday"];  
  12.   var day = new Date();  
  13.   var TodayDay = Wday[day.getUTCDay()];  
  14.   var span = document.createElement("span");  
  15.   span.style.color = "green";  
  16.   span.innerText = "getUTCDay Method \n The day of the week, According to UTC-> " + TodayDay + "\n";  
  17.   document.body.appendChild(span);  
  18.  };  
  19.  return getUTCDate_getUTCDay;  
  20. })();  
  21. window.onload = function() {  
  22.  var obj = new getUTCDate_getUTCDay();  
  23.  obj.getUTCDate();  
  24.  obj.getUTCDay();  
  25. };  
Output
 
result.jpg


Similar Articles