escribo una función para obtener los días del mes. Uso dayjs y jalaliday para construir esta función.
Mi código:
import dayjs from "dayjs"; import jalaliday from 'jalaliday' dayjs.extend(jalaliday) dayjs.calendar('jalali').locale('fa') export function GetMonth(month =dayjs().month()){ const year = dayjs().year(); const FirstDayOfTheMonth= dayjs(new Date(year ,month,1)).calendar('jalali').day(); let CurrentMonthCount =0 -FirstDayOfTheMonth; const DaysMatrix =new Array(5).fill([]).map(()=>{ return new Array(7).fill(null).map(()=>{ CurrentMonthCount++ return dayjs(new Date(year,month,CurrentMonthCount)).calendar('jalali').locale('fa') }) }); return DaysMatrix; }uso esta función en mi componente de reacción y, cuando registro esta función, me da una fecha en inglés como esta:
solo el año es correcto. ¿Cómo puedo obtener detalles de la fecha persa?
prueba este hombre:
import dayjs from "dayjs"; import jalaliday from 'jalaliday' dayjs.extend(jalaliday) export function GetMonth(month = dayjs().month()+1) { const year = dayjs().year(); const FirstDayOfTheMonth = dayjs(new Date(year, month, 1)).day(); let CurrentMonthCount = 0 - FirstDayOfTheMonth; const DaysMatrix = new Array(5).fill([]).map(() => { return new Array(7).fill(null).map(() => { CurrentMonthCount++ return dayjs(new Date(year,month,CurrentMonthCount)).calendar('jalali').locale('fa').format('DD MMMM YYYY') }) }); return DaysMatrix }