Date Object Method In TypeScript: Part 5
Before reading this article, please go through the following articles:
Introduction
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.
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
- Date.getUTCDate()
Function
- getUTCDate() {
- var date = new Date();
- var span = document.createElement("span");
- span.style.color = "Blue";
- span.innerText = "getUTCDate Method \n The day of the month, According to UTC-> " + date.getUTCDate() + "\n";
- document.body.appendChild(span);
- }
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
- Date.getUTCDay()
- getUTCDay() {
- var Wday: string[] = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
- var day = new Date();
- var TodayDay = Wday[day.getUTCDay()];
- var span = document.createElement("span");
- span.style.color = "green";
- span.innerText = "getUTCDay Method \n The day of the week, According to UTC-> " + TodayDay + "\n";
- document.body.appendChild(span);
- }
Complete Program
getUTCDate_getUTCDay.ts
- class getUTCDate_getUTCDay {
- getUTCDate() {
- var date = new Date();
- var span = document.createElement("span");
- span.style.color = "Blue";
- span.innerText = "getUTCDate Method \n The day of the month, According to UTC-> " + date.getUTCDate() + "\n";
- document.body.appendChild(span);
- }
- getUTCDay() {
- var Wday: string[] = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
- var day = new Date();
- var TodayDay = Wday[day.getUTCDay()];
- var span = document.createElement("span");
- span.style.color = "green";
- span.innerText = "getUTCDay Method \n The day of the week, According to UTC-> " + TodayDay + "\n";
- document.body.appendChild(span);
- }
- }
- window.onload = () => {
- var obj = new getUTCDate_getUTCDay();
- obj.getUTCDate();
- obj.getUTCDay();
- };
getUTCDate_getUTCDay_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="getUTCDate_getUTCDay.js"></script>
- </head>
- <body>
- <h3>getUTCDate and getUTCDay method in TypeScript</h3>
- <div id="content"></div>
- </body>
- </html>
getUTCDate_getUTCDay.js
- var getUTCDate_getUTCDay = (function() {
- function getUTCDate_getUTCDay() {}
- getUTCDate_getUTCDay.prototype.getUTCDate = function() {
- var date = new Date();
- var span = document.createElement("span");
- span.style.color = "Blue";
- span.innerText = "getUTCDate Method \n The day of the month, According to UTC-> " + date.getUTCDate() + "\n";
- document.body.appendChild(span);
- };
- getUTCDate_getUTCDay.prototype.getUTCDay = function() {
- var Wday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
- var day = new Date();
- var TodayDay = Wday[day.getUTCDay()];
- var span = document.createElement("span");
- span.style.color = "green";
- span.innerText = "getUTCDay Method \n The day of the week, According to UTC-> " + TodayDay + "\n";
- document.body.appendChild(span);
- };
- return getUTCDate_getUTCDay;
- })();
- window.onload = function() {
- var obj = new getUTCDate_getUTCDay();
- obj.getUTCDate();
- obj.getUTCDay();
- };
Output


Comments
Join the conversation! Your thoughts help the community grow.