get solar year in react

212 views Asked by At

how can I get current solar year local fa (not full date) in react?

I just need to get solar year (jalali) and I'm using this:

new Date().toLocaleDateString('fa-IR');

but it return current date (24/04/1399). I just want (1399)

3

There are 3 answers

0
Max Smirnov On BEST ANSWER

You can pass additional options, and transform output as you want

new Date().toLocaleDateString('fa-IR', {year: 'numeric'} );
3
Nick McCurdy On
new Date().getFullYear(); // 2020
0
Zahra Talebi On

I find that. the answer is :

new Date().toLocaleDateString("fa-IR", {year: "numeric" });

the above code return 1399. (current jalali year (persian date))