似乎是一項艱鉅的任務。根據this discussion at bytes.com沒有明確的方法來完成100%正確的轉換。但是,他們認爲印度教曆法只有364天而不是365天(或閏年366天),這似乎是錯誤的。
在這裏你可以找到一個好的轉換表,包括處理閏年:http://hinduism.about.com/od/basics/a/monthsdayseras.htm
如果它是那麼容易,因爲寫在那裏,你可以嘗試這樣的事情(PHP代碼):
<?php
function convertDateToHinduDate($date) {
$beginningDayOfMonth = array(
1 => 21,
2 => 20,
3 => 22 + (dateIsLeapYear($date) ? -1 : 0), /* 21 in leap years */
4 => 21,
5 => 22,
6 => 22,
7 => 23,
8 => 23,
9 => 23,
10 => 23,
11 => 22,
12 => 22,
);
$daysOfHinduMonth = array(
1 => 30 + (dateIsLeapYear($date) ? 1 : 0), /* 31 in leap years */
2 => 31,
3 => 31,
4 => 31,
5 => 31,
6 => 31,
7 => 30,
8 => 30,
9 => 30,
10 => 30,
11 => 30,
12 => 30,
);
$day = (int) date('d', strtotime($date));
$month = (int) date('m', strtotime($date));
$year = (int) date('Y', strtotime($date));
$monthBefore = $day < $beginningDayOfMonth[$month];
$yearBefore = $month < 3 || ($month == 3 && $day < $beginningDayOfMonth[3]);
$newYear = $year + 57 + ($yearBefore ? -1 : 0);
$newMonth = $month - 2 + ($monthBefore ? -1 : 0);
if($newMonth < 1) $newMonth = 12 + $newMonth;
$newDay = $day - $beginningDayOfMonth[$month];
if($newDay < 1) $newDay = $daysOfHinduMonth[$newMonth] + $newDay;
return date("d-m-Y", mktime(11, 59, 0, $newMonth, $newDay, $newYear));
}
function dateIsLeapYear($date) {
return date('L', strtotime($date));
}
$date = date("d-m-Y", strtotime('2012-01-28'));
echo 'Date: ', $date, ' (is leap year: ', dateIsLeapYear($date) ? 'yes' : 'no', ')<br />';
echo 'Converted Hindu date: ', convertDateToHinduDate($date);
?>
這段代碼的輸出:
Date: 28-01-2012 (is leap year: yes)
Converted Hindu date: 07-11-2068
但根據this Java applet計算器,應該是2068年5月11日,而不是2068年7月11日。所以,仍然存在一些轉換規則。也許你可以給我更多的信息,以便我可以更正上面的代碼。
請給出示例值如何表示日期(時間戳),當你寫它*印度日曆*風格。 – hakre 2011-12-27 15:04:35
從日,月,年到日,月,年對我們的應用程序來說已經足夠了。 – 2011-12-27 15:07:54
這不是我想知道的。只給出多個例子,左邊是印度教日期,右邊是相應的格利高裏日期。我只想知道印度日曆是什麼時候在網站上表示日期值。 – hakre 2011-12-28 08:50:46