How to change Gregorian date to Persian date in JavaScript?

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' };
let today = new Date().toLocaleDateString('fa-IR', options);
console.log(today);

and in order to convert characters to Latin digits you can do (as Amir Fo mentioned) :

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

Leave a Comment