How to change Gregorian date to Persian date in JavaScript?

myname picture myname · Feb 23, 2016 · Viewed 25.4k times · Source

Can anyone help me to change Gregorian date to Persian in JavaScript? I want to use it in HTML and JavaScript.

Answer

Ali_Hr picture Ali_Hr · Aug 27, 2019

You can use toLocaleDateString();

let today = new Date().toLocaleDateString('fa-IR');
console.log(today);

fa-IR is for Farsi-Iran,

other dates is as follow:

en-US: For English

hi-IN: For Hindi

...

also you can set options as second argument, for example:

let options = { year: 'numeric', month: 'long', day: 'numeric' };
new Date().toLocaleDateString('fa-IR', options);