🌐
HowToDoInJava
howtodoinjava.com › home › typescript › typescript date
TypeScript Date (with Examples)
August 29, 2023 - const currentDate = new Date(); ... 6) in UTC. getUTCMonth(): returns the month (0 – 11) in UTC. getUTCYear(): returns the year (usually 2–3 digits) in UTC....
🌐
Reactgo
reactgo.com › home › getting the current year using typescript
Getting the current Year using TypeScript | Reactgo
September 7, 2023 - We can get the current year in TypeScript by calling a getFullYear() method on a new Date() constructor.
🌐
SPGuides
spguides.com › get-month-day-year-from-date-in-typescript
How to Get month day year from date in Typescript
June 29, 2025 - Here is the Typescript code to get the year from the date in Typescript. let year = currentDate.getFullYear(); console.log(`The year is: ${year}`);
🌐
Scaler
scaler.com › home › topics › typescript › typescript date object
Typescript Date Object - Scaler Topics
May 17, 2024 - getUTCHours() : This method in ... specified date according to universal time. getUTCFullYear() : It is used to return the year on the specified date according to universal time....
🌐
Futurestud.io
futurestud.io › tutorials › get-the-current-year-in-javascript-or-node-js
Get the Current Year in JavaScript or Node.js
The JavaScript engine comes with a global Date class. Interacting with dates is an essential part of programming. JavaScript’s Date comes with two methods to retrieve the current year: Date#getYear and Date#getFullYear.
🌐
C# Corner
c-sharpcorner.com › UploadFile › 5089e0 › date-object-method-in-typescript-part-2
Date Object Method In TypeScript: Part 2
October 14, 2019 - In TypeScript, The getFullYear() method of the date object will return the year of the specified date or the current year.
🌐
W3Schools
w3schools.com › jsref › jsref_getfullyear.asp
W3Schools.com
new Date() constructor getDate() getDay() getFullYear() getHours() getMilliseconds() getMinutes() getMonth() getSeconds() getTime() getTimezoneOffset() getUTCDate() getUTCDay() getUTCFullYear() getUTCHours() getUTCMilliseconds() getUTCMinutes() getUTCMonth() getUTCSeconds() now() parse() prototype setDate() setFullYear() setHours() setMilliseconds() setMinutes() setMonth() setSeconds() setTime() setUTCDate() setUTCFullYear() setUTCHours() setUTCMilliseconds() setUTCMinutes() setUTCMonth() setUTCSeconds() toDateString() toISOString() toJSON() toLocaleDateString() toLocaleTimeString() toLocaleString() toString() toTimeString() toUTCString() UTC() valueOf() JS Function
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › getFullYear
Date.prototype.getFullYear() - JavaScript | MDN
const moonLanding = new Date("July 20, 69 00:20:18"); console.log(moonLanding.getFullYear()); // Expected output: 1969 ... An integer representing the year for the given date according to local time.
Find elsewhere
🌐
Bobby Hadz
bobbyhadz.com › blog › typescript-get-current-date-and-time
How to get the current Date and Time in TypeScript | bobbyhadz
Copied!function padTo2Digits(num: ... hh:mm:ss) console.log(formatDate(new Date('May 04, 2025 05:24:07'))); ... Date.getFullYear method - returns a four-digit number representing the year that corresponds to a ...
🌐
Altcademy
altcademy.com › blog › how-to-get-current-year-in-javascript
How to get current year in JavaScript
June 9, 2023 - In this blog post, we'll learn how to get the current year in JavaScript. This is a simple yet important task when working with date and time in web development. By the end of this tutorial, you'll be able to retrieve the current year and manipulate it as needed for
Top answer
1 of 3
18

You can use Date():

this.curdate = (new Date().getMonth() + 1).toString() + '-' + new Date().getFullYear().toString();

Note that new Date().getMonth() start from 0 to 11 so you need to +1 to make it 1 to 12.

Update:

To add leading 0 based on related post you can do: '0' + (new Date().getMonth() + 1).toString().slice(-2)

Explanation:

Since '0' is not a number but a string when you add (+) with another string then it would be concatenated. Then .slice(-2) gives us the last two characters of the string. If it's single digit then it would be 0xmonth, if it's double digits then it would be 0 + xx month which are returned.

See snippet for example:

var d = '0' + (new Date().getMonth() + 1).toString().slice(-2) + '-' + new Date().getFullYear().toString();
document.getElementById("demo").innerHTML = d;
<p id="demo"></p>

Alternatively if you don't want a trailing 0 on double digit months (Oct, Nov, Dec) you could do a little checking based on month digit length: (new Date().getMonth() + 1).length > 1 ? new Date().getMonth() + 1 : '0' + (new Date().getMonth() + 1)

var month = (new Date().getMonth() + 1).length > 1 ? new Date().getMonth() + 1 : '0' + (new Date().getMonth() + 1);
var date = (month).toString().slice(-2) + '-' + new Date().getFullYear().toString();
document.getElementById("demo").innerHTML = date;
<p id="demo"></p>

2 of 3
5

You can use the built-in date pipe:

{{date | date:'MM-dd'}}

and pass your own format.
Update
Try something like for a JS-only solution:

m = new Date().getMonth().toString() + 1;
y = new Date().getFullYear().toString();
return m + '-' + y;
🌐
TutorialsPoint
tutorialspoint.com › typescript › typescript_date_object.htm
TypeScript - Date Object
year, month, day, hour, minute, second, milli_second: The Date() constructor creates a new date based on these parameters. The Date constructor returns the Date string based on the parameters passed.
🌐
Javatpoint
javatpoint.com › typescript-date-object
Typescript Date Object - javatpoint
Typescript Date Object with typescript tutorial, typescript introduction, versions, typescript and javascript, features, components, installation, typescript first program, typescript types, etc.
🌐
Scaler
scaler.com › home › topics › get current year in javascript
Get the Current Year in JavaScript - Scaler Topics
May 4, 2023 - This number represents the current year of the given date and local time. There are various methods that can be used to get a data object. These methods are called on these objects. Using these methods, we can fetch the current day, month, or year for any particular date object.
🌐
Delft Stack
delftstack.com › home › howto › typescript › typescript current date
How to Get Current Date and Time in TypeScript | Delft Stack
February 2, 2024 - The Date.getFullYear() method gave back a four-digit number denoting the year related to a date.
🌐
W3docs
w3docs.com › javascript
How Get the Current Year in JavaScript
To get the current year, you can call the getFullYear() method will return the year of the specified Date according to local time. The value returned by is an absolute number.