Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138163

How to extract only the year from a date string?

$
0
0

Is there a way to grab only the first four characters of a date string from an API in JavaScript?

Back story

I am using The Movie Database, which allows me to get the exact release dates of movies. For instances, I get the following object of data for "Finding Nemo":

enter image description here

I've added the following code in my Movies.js component, <p>({movie.release_date})</p> and it returns 2003-05-30 as expected.

But is there a way to extract only the first four characters (2003) and return only that? Or better yet, is there a way to extract only the release year?


Viewing all articles
Browse latest Browse all 138163

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>