Moment JS Get Year from Date Example
This simple article demonstrates of moment js get year from date. i explained simply step by step moment js get year from date. let’s discuss about get year from date moment jquery. i explained simply about jquery moment get year from date. Here, Creating a basic example of how to get year from date in moment js.
Here, i will give you simple example of jquery moment js get year from date using format('YYYY').
let's see both example with output:
Example:
<!DOCTYPE html>
<html>
<head>
<title>jquery moment example - ItSolutionStuff.com</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" crossorigin="anonymous"></script>
</head>
<body>
<h1>jquery moment example - ItSolutionStuff.com</h1>
</body>
<script type="text/javascript">
var oneDate = moment('02-01-2021', 'DD-MM-YYYY');
var yearName = oneDate.format('YYYY');
console.log(yearName);
var oneDate = moment();
var yearName = oneDate.format('YY');
console.log(yearName);
</script>
</html>
Output:
2021
21
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Moment JS Get All Dates in Month Example
- Get All Dates Between Two Dates in Moment JS
- Moment JS Get Current Week Start and End Date Example
- Moment Difference Between Two Dates in Hours Minutes and Seconds
- Moment JS Difference Between Two Dates In Years, Months, Days
- Moment JS Check if Date is Past or not Example
- JQuery Moment JS Subtract Seconds to Datetime Example
- JQuery Moment Add Seconds to Datetime Example
- JQuery Moment Add Month to Date Example
- JQuery Moment Add Days to Date Example
- JQuery Moment Get Current Date Example