Date Object Method In TypeScript: Part 9
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 "setFullYear" method in the TypeScript.
setFullYear() Method
In TypeScript, the setFullYear() method of the date object sets the year of the specified date according to the local time. We can also set the month and day of the month by this method.
Syntax
- Date.setFullYear(yearvalue,monthvalue,dayvalue)
- yearValue : It is the required parameter. A year is represented by a four-digit value. For example, in 2012.
- monthValue : It is the optional parameter. Months are represented by an integer value between 0 and 11. 0 is January, 1 is February and so on.
- dayValue : It is an optional parameter. A day of month is represented by an integer between 1 and 31. If you provide the dayValue parameter then you must also provide the monthValue.
Function
- setfullyear() {
- var year = new Date();
- var span = document.createElement("span");
- span.innerText = "Current year is -> " + year + "\n";
- document.body.appendChild(span);
- year.setFullYear(2007);
- var span = document.createElement("span");
- span.style.color = "Blue";
- span.innerText = "After set year is -> " + year + "\n";
- document.body.appendChild(span);
- }
Complete Program
setFullYear.ts


Join the conversation! Your thoughts help the community grow.