Easiest way is to call it with 3 arguments (year, month, day).
Do note that
month is the month index (0 based), so November (11th month) is actually 10th in the format that Date expects.
new Date(2019, 10, 30).getFullYear() % 100; // returns 19;
If you can't do it this way and you simply must work around the string format mentioned, then you can just do
const dateString = '30.11.2019'; const year = dateString.substring(dateString.length-2);
You can get last two digits with the following code:
var strDate = new Date(); // By default Date empty constructor give you Date.now var shortYear = strDate.getFullYear(); // Add this line var twoDigitYear = shortYear.toString().substr(-2);
Since the string you're using isn't in a format recognized by
Date.parse() (more on that here), you need to manually create that Date object.
const strDate = '30.11.2019'; let [d,m,y] = strDate.split(/\D/); const date = new Date(y, --m, d); console.log(date.getFullYear())
do not need split string, I think. using moment
yarn add moment
const moment = require( 'moment' ); const simpleYear = moment( "30.11.2019", "DD.MM.YYYY" ).format( "YY" ); console.log( "simpleYear = " + simpleYear );
Date.prototype.getYear(), Hello,I have problem because I cannot find the solution with 2 digits for Join Date: Mar 2011; Posts: 6; Thanks: 1: Thanked 0 Times in 0 Posts� How to extract last(end) digit of the Number value using jquery. because i have to check the last digit of number is 0 or 5. so how to get last digit after decimal point. For Ex. var test = 2354.55 Now how to get 5 from this numeric value using jquery. i tried substr but that is only work for string not for Number format
var strDate = "30.11.2019"; var lastdigit = strDate.slice(-2);