0

I have a date in this format 1379/10/02 Now I want to turn this date into AD That is, the date 2000/4/29

I also use the momentJs library Please help me if possible by using this library Thank you for your time

davood beheshti
  • 213
  • 1
  • 11
  • 1
    Try this solution here: https://stackoverflow.com/questions/71421825/how-to-convert-persian-jalali-dates-to-other-18-calendar-dates-in-javascript-w – Mohsen Alyafei Jul 21 '22 at 07:06

1 Answers1

0

You can use jalaali-js or moment-jalaali or jalali-date (via) or Ali Amini's or Mohsen Alyafei's solution. Or draw inspiration from related questions. People not knowing Persian culture can get confused by the multiple names for the calendar - Jalali, Persian, Khorshidi, Shamsi. Maybe you can elaborate the differences a bit?

Here is a modern solution using the Skypack CDN for easy npm package access in the browser. Just remember to always declare your variables with const/let/var and no global ones inside es6-modules:

<script type="module">
import jalaali from 'https://cdn.skypack.dev/jalaali-js'
import jMoment from 'https://cdn.skypack.dev/moment-jalaali'


// jalaali-js
let g = jalaali.toGregorian(1379, 2, 10);
let j = jalaali.toJalaali(new Date(2000, 4-1, 29)) // january is month 0

// moment-jalaali
let moment = jMoment('1379/2/10', 'jYYYY/jM/jD') // Parse a Jalaali/Shamsi date
let gregorian = moment.format('jYYYY/jM/jD [is] YYYY/M/D')


console.log('jalaali-js version:',g,j,'moment-jalaali version: ', gregorian)
</script>
cachius
  • 1,743
  • 1
  • 8
  • 21