How To Get Current Year 2 Digit in JavaScript

JavaScript

Nicesnippets

79

17-07-2021


How To Get Current Year 2 Digit in JavaScript

Hello Friends,

Now let's see example of how to use javascript get current year 2 digit example. We will use how to use if get current year 2 digit in javascript. Here you will learn how to use javascript get current year 2 digit. This is a short guide on get current year 2 digit. Let's get started with how to get current year 2 digit in javascript.

Here i will give you many example how you can check javascript get current year 2 digit.

Example: 1


<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="utf-8">

<title>How to get current year 2 digin in javascript?</title>

<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">

</head>

<body>

<script type = "text/javascript">

var date = new Date();

var getYear = date.getFullYear();

var getTwodigitYear = getYear.toString().substring(2);

alert(getTwodigitYear );

</script>

</body>

</html>

Output:

21

Example: 2

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="utf-8">

<title>How to get current year 2 digin in javascript?</title>

<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">

</head>

<body>

<script type = "text/javascript">

console.log(new Date().getFullYear().toString().substr(-2));

</script>

</body>

</html>

Output:

21

It will help you....


Recommended Posts