gpt4 book ai didi

javascript - 获取波斯月的最后一天 + 解决方案

转载 作者:行者123 更新时间:2023-12-05 02:00:01 27 4
gpt4 key购买 nike

在浏览网页后,我找不到任何功能来执行此操作,我有可行的个人解决方案。也许它对某人有用。

**使用 Moment 插件转换日期。***moment(currentPersianDate).clone().endof('month').format('YYYY/MM/DD') => 不适用于波斯语日期

  function GetLastDayOfPersianMonth(calendar) {
const currentDate = new Date();
const currentPersianDate = moment(currentDate).locale('fa').format('YYYY/M/D');
const splitDate = currentPersianDate.split("/");
const year = splitDate[0];
const month = splitDate[1];
const lastDayOfPersianMonth = CalculateLeapYear(month, year);

const endPersianMonth = year + "/" + month + "/" + lastDayOfPersianMonth;
};

function CalculateLeapYear(month, year) {
if (month <= 6) {
return 31;
}
if (month > 6 && month < 12) {
return 30;
}

const leapMatch = [1, 5, 9, 13, 17, 22, 26, 30];
const number = year % 33;
const isLeap = leapMatch.includes(number);

if (month == 12 && !isLeap) {
return 29;
}
if (month == 12 && isLeap) {
return 30;
}
}

最佳答案

您可以在 C# 中使用此代码我的网站 https://mohammadhosseinaref.ir

        public static string PersianDayOfWeek(DayOfWeek dayOfWeek)
{
switch (dayOfWeek)
{
case DayOfWeek.Sunday:
return "یکشنبه";
case DayOfWeek.Monday:
return "دوشنبه";
case DayOfWeek.Tuesday:
return "سه شنبه";
case DayOfWeek.Wednesday:
return "چهار شنبه";
case DayOfWeek.Thursday:
return "پنج شنبه";
case DayOfWeek.Friday:
return "جمعه";
case DayOfWeek.Saturday:
return "شنبه";
default:
return null;
}
}

public static Dictionary<int, string> ListOfPersianDayOfMonth(int month, int years)
{
Dictionary<int, string> dicDays = new Dictionary<int, string>();

PersianCalendar p = new PersianCalendar();

var dates = Enumerable.Range(1, p.GetDaysInMonth(years, month))
.Select(day => ParsePersianToGorgian(years + "/" + month + "/" + day))
.ToList();

foreach (var item in dates)
{
var day = GeorgianToPersian(item.Value, ShowMode.OnlyDate);
dicDays.Add(int.Parse(day.Split('/')[2]), DayPersian(item.Value.DayOfWeek) + " " + day);
}
return dicDays;
}

关于javascript - 获取波斯月的最后一天 + 解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67565335/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com