using Intl.dateTimeFormat()
for indian month name and date
const fullHindi = {
weekday: 'long',
dayPeriod: 'long',
year: 'numeric',
month: 'short',
day: 'numeric',
dayPeriod: "narrow",
hour: '2-digit',
minute: '2-digit',
second: 'numeric',
calendar: 'indian',
timeZone: 'Asia/Kolkata',
numberingSystem: 'deva',
formatMatcher: 'basic',
hourCycle: 'h24',
};
const samay = new Intl.DateTimeFormat("hi", fullHindi);
const today = new Date();
const hindi = samay.format(today);
console.log({hindi}); // शक मंगलवार, २२ श्रावण १९४६, २३:४४:०८
but its not correct though its Shuka/Saptami शुक्ल सप्तमी
i.e. in india date are till 15 and then it changes to diffrent paksha ( either Shukla/Krishna ) see more details here
so my ask is is there any format option configuration is there which change this; just like h12 and h24 format
I Think this is the output you expext
const getPaksha = (date) => {
const day = date.getDate();
return day <= 15 ? 'Shukla' : 'Krishna';
};
const getTithi = (date) => {
const day = date.getDate();
return `Tithi ${day}`;
};
const getHinduMonthAndYear = (date) => {
const months = [
'Chaitra', 'Vaishakha', 'Jyeshtha', 'Ashadha', 'Shravana', 'Bhadrapada',
'Ashvin', 'Kartika', 'Margashirsha', 'Pushya', 'Magha', 'Phalguna'
];
const monthIndex = (date.getMonth() + 1) % 12;
return { month: months[monthIndex], year: date.getFullYear() };
};
const formatHinduDate = (date) => {
const paksha = getPaksha(date);
const tithi = getTithi(date);
const { month, year } = getHinduMonthAndYear(date);
return `${paksha} Paksha, ${tithi}, ${month}, ${year}`;
};
const today = new Date();
const formattedDate = formatHinduDate(today);
console.log(formattedDate);