我如何能配合回历
问题描述:
我想告诉贾拉利日历和回历的同时贾利利压延机,但我不知道如何贾拉利天,回历天相匹配。我搜索并找到了下面的源代码。它显示日历日历,但我不知道如何匹配两个日历。 Hijri日历几个月没有任何特定的模式。我如何能配合回历
import javax.swing.JOptionPane;
public class TestCal {
/** Main method */
public static void main(String[] args) {
// Prompt the user to enter year
String yearString = JOptionPane.showInputDialog(
"Lotfan Sale morede nazar ra vared konid (Masalan 1390):");
// Convert string into integer
int year = Integer.parseInt(yearString);
// Prompt the user to enter month
String monthString = JOptionPane.showInputDialog(
"Lotfan mahe khod ra niz az miane adade 1 ta 12 bargozinid:");
// Convert string into integer
int month = Integer.parseInt(monthString);
// Print calendar for the month of the year
printMonth(year, month);
}
/** Print the calendar for a month in a year */
static void printMonth(int year, int month) {
// Print the headings of the calendar
printMonthTitle(year, month);
// Print the body of the calendar
printMonthBody(year, month);
}
/** Print the month title, e.g., May, 1999 */
static void printMonthTitle(int year, int month) {
System.out.println(" " + getMonthName(month)
+ " " + year);
System.out.println("-----------------------------");
System.out.println(" Sun Mon Tue Wed Thu Fri Sat");
}
/** Get the English name for the month */
public static String getMonthName(int month) {
String monthName = null;
switch (month) {
case 1: monthName = "Farvardin"; break;
case 2: monthName = "Ordibehesht"; break;
case 3: monthName = "Khordad"; break;
case 4: monthName = "Tir"; break;
case 5: monthName = "Mordad"; break;
case 6: monthName = "Shahrivar"; break;
case 7: monthName = "Mehr"; break;
case 8: monthName = "Aban"; break;
case 9: monthName = "Azar"; break;
case 10: monthName = "Dey"; break;
case 11: monthName = "Bahman"; break;
case 12: monthName = "Esfand";
}
return monthName;
}
/** Print month body */
public static void printMonthBody(int year, int month) {
// Get start day of the week for the first date in the month
int startDay = getStartDay(year, month);
// Get number of days in the month
int numberOfDaysInMonth = getNumberOfDaysInMonth(year, month);
// Pad space before the first day of the month
int i = 0;
for (i = 0; i < startDay; i++)
System.out.print(" ");
for (i = 1; i <= numberOfDaysInMonth; i++) {
if (i < 10)
System.out.print(" " + i);
else
System.out.print(" " + i);
if ((i + startDay) % 7 == 0)
System.out.println();
}
System.out.println();
}
/** Get the start day of the first day in a month */
public static int getStartDay(int year, int month) {
// Get total number of days since 1/1/1800
int startDay1300 = 1;
int totalNumberOfDays = getTotalNumberOfDays(year, month);
// Return the start day
return (totalNumberOfDays + startDay1300) % 7;
}
/** Get the total number of days since Jan 1, 1800 */
static int getTotalNumberOfDays(int year, int month) {
int total = 0;
// Get the total days from 1800 to year - 1
for (int i = 1300; i < year; i++)
if (isLeapYear(i))
total = total + 366;
else
total = total + 365;
// Add days from Jan to the month prior to the calendar month
for (int i = 1; i < month; i++)
total = total + getNumberOfDaysInMonth(year, i);
return total;
}
/** Get the number of days in a month */
public static int getNumberOfDaysInMonth(int year, int month) {
if (month <= 6 && month > 0)
return 31;
else if (month < 12 && month > 6)
return 30;
if (month == 12) return isLeapYear(year) ? 30 : 29;
return 0; // If month is incorrect
}
/** Determine if it is a leap year */
public static boolean isLeapYear(int year) {
return year % 400 == 0 || (year % 4 == 3 && year % 100 != 0);
}
}
答
一个非常简单的方法:
- 采取两种历法
- 之间共同发展的时代/查找算法,日历转换日期/从那个时代之间的天数。从日历型
- 转换日期为划时代的三角洲和划时代增量到日历类型B.
我实现了一个简单的C库在各种日历日期之间的转换。代码可用here。您可以提取算法并以您选择的语言来实现它们。如果您使用的是C/C++,你可以简单地说:
#include <calendars/cl-calendar.h>
int16_t year;
uint8_t month;
uint16_t day;
convert_date(CAL_ISLAMIC_CIVIL, CAL_SOLAR_HIJRI,
1396, 7, 11, &year, &month, &day);
printf("1396/07/11 AP is: %d/%d/%d Hijri", year, month, day);
,它将打印:
$ 1396/07/11 AP is: 1439/1/12 Hijri
注:
- 贾拉利日历不再使用。您可能想要使用Solar Hijri日历。
- Hijri日历不是表格。你可能意味着你的贾拉利日历*民事Clanndar
闰年规则显然是非常相似的阳历,因此不正确的。当然,Jalali(波斯语)和Hijri日历的月份并不完全相关(Jalali严格按照春分,而Hijri是严格的月球)。您还应该考虑Hijri日历有多种变体(您是否想要沙特阿拉伯或其他什么?)。请提供更多关于你想要的细节。两个日历之间唯一的共同点就是自某个时代以来的天数(允许进行数学转换)。 –
你也可以使用我的库[Time4J](https://github.com/MenoData/Time4J)(使用ui-module)并在用户界面中嵌入两个图形JavaFX日历,一个用于Persian,一个用于Hijri,然后同步两个日历,也看到了[javadoc的(http://time4j.net/javadoc-en/net/time4j/ui/javafx/CalendarPicker.html) –
我知道贾拉利闰年是回历(沙特阿拉伯不同)和该代码工作正常波斯日历,但想在这个环节http://www.time.ir/我想同步杰拉里天,回历天在同一时间日历,因为在波斯历法一些假期是回历节假日和我想在我的程序中以不同的颜色显示它们。 – Muskan