get solar year in react

219 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 best solutions below

0
On BEST ANSWER

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

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

I find that. the answer is :

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

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