jalali-moment icon indicating copy to clipboard operation
jalali-moment copied to clipboard

After converting, the date always comes back one day off

Open darushHamidi opened this issue 2 years ago • 3 comments

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

darushHamidi avatar Jul 03 '22 09:07 darushHamidi

try this:

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

aroshanzamir avatar Jul 12 '22 06:07 aroshanzamir

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

fingerpich avatar Jul 14 '22 08:07 fingerpich

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

amirhosein993 avatar Jun 10 '23 05:06 amirhosein993