Date Object Method In TypeScript: Part 3
Before reading this article, please go through the following articles:
Introduction
In this article, I am describing the date object's "getMonth" and "getSeconds" method in the TypeScript.
getMonth() Method
Syntax
- Date.getMonth()
Function
- getMonth() {
- var CurrntMonth: string[] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", ];
- var month = new Date();
- var CrrntMonth = CurrntMonth[month.getMonth()];
- var span = document.createElement("span");
- span.style.color = "Blue";
- span.innerText = "getMonth Method \n Current Month is-> " + CrrntMonth + "\n";
- document.body.appendChild(span);
- }
getSeconds() Method
In TypeScript, the getSeconds() method returns the seconds of the specified date and time or the current date and time. The returned value is an integer number between 0 and 59.
Syntax
- Date.getSeconds()
- getSecond() {
- var second = new Date();
- var span = document.createElement("span");
- span.innerText = "getSeconds Method \n The Seconds of the time right now-> " + second.getSeconds() + "\n";
- document.body.appendChild(span);
- }
Complete Program
getMonth_getSeconds.ts
- class getMonth_getSeconds {
- getMonth() {
- var CurrntMonth: string[] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", ];
- var month = new Date();
- var CrrntMonth = CurrntMonth[month.getMonth()];
- var span = document.createElement("span");
- span.style.color = "Blue";
- span.innerText = "getMonth Method \n Current Month is-> " + CrrntMonth + "\n";
- document.body.appendChild(span);
- }
- getSecond() {
- var second = new Date();
- var span = document.createElement("span");
- span.innerText = "getSeconds Method \n The Seconds of the time right now-> " + second.getSeconds() + "\n";
- document.body.appendChild(span);
- }
- }
- window.onload = () => {
- var obj = new getMonth_getSeconds();
- obj.getMonth();
- obj.getSecond();
- };
getMonth_getSeconds_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="getMonth_getSeconds.js"></script>
- </head>
- <body>
- <h3>getMonth and getSeconds method in TypeScript</h3>
- <div id="content"></div>
- </body>
- </html>
getMonth_getSeconds.js
- var getMonth_getSeconds = (function() {
- function getMonth_getSeconds() {}
- getMonth_getSeconds.prototype.getMonth = function() {
- var CurrntMonth = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", ];
- var month = new Date();
- var CrrntMonth = CurrntMonth[month.getMonth()];
- var span = document.createElement("span");
- span.style.color = "Blue";
- span.innerText = "getMonth Method \n Current Month is-> " + CrrntMonth + "\n";
- document.body.appendChild(span);
- };
- getMonth_getSeconds.prototype.getSecond = function() {
- var second = new Date();
- var span = document.createElement("span");
- span.innerText = "getSeconds Method \n The Seconds of the time right now-> " + second.getSeconds() + "\n";
- document.body.appendChild(span);
- };
- return getMonth_getSeconds;
- })();
- window.onload = function() {
- var obj = new getMonth_getSeconds();
- obj.getMonth();
- obj.getSecond();
- };
Output


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