fingerpich / jalali-moment

Display, parse, manipulate, validate and convert jalali (Persian, Khorshidi, Shamsi) or Gregorian (Miladi) dates and times.
https://fingerpich.github.io/jalali-moment/
MIT License
434 stars 68 forks source link

After converting, the date always comes back one day off #126

Open darushHamidi opened 2 years ago

darushHamidi commented 2 years ago

I convert the Shamsi date to gregorian date with the following snippet:

var m = moment.from('1401/6/1', 'fa', 'YYYY/MM/DD');
const result = m.locale('en').format('YYYY/MM/DD'); // 2022/08/23

Now, the day is 23, After converting the result to the date object the day will get 22, Why? const date = new Date(result); // 2022-08-22T19:30:00.000Z

aroshanzamir commented 2 years ago

try this:

const date = moment.from(persianDate, 'fa', 'YYYY/MM/DD').locale('en').format('YYYY/MM/DD').replace(/\//g, '-');
console.log(new Date(date))
fingerpich commented 2 years ago

Hi please create a demo for the issues I have created a demo and seems it works well https://stackblitz.com/edit/jalali-moment-demo-react-iewto2?file=index.js

amirhosein993 commented 1 year ago

I have the same issue. When converting a gregorian date to persian date. The date comes back !