2011-12-27 97 views
43

我怎麼能轉換unix時間Hindu calendar­Wikipedia時間和其他方式輪phpPerlPythonJava?我知道我可以轉換成HebrewJewish。但Hindu不是一個選項。轉換和從印度日曆

更具體地說,我在談論印度教農曆。以下網站正在運行,並且完全符合我的要求:http://web.meson.org/calendars/。例如,它將'28-1-2012(公曆)'轉換爲5-11-2068(Hind.Lun。)。我怎樣才能完成同樣的任務?如果那裏絕對沒有任何問題,我怎麼能自己寫呢?

+0

請給出示例值如何表示日期(時間戳),當你寫它*印度日曆*風格。 – hakre 2011-12-27 15:04:35

+0

從日,月,年到日,月,年對我們的應用程序來說已經足夠了。 – 2011-12-27 15:07:54

+1

這不是我想知道的。只給出多個例子,左邊是印度教日期,右邊是相應的格利高裏日期。我只想知道印度日曆是什麼時候在網站上表示日期值。 – hakre 2011-12-28 08:50:46

回答

8

紙:Indian Calendrical Calculations
提供的附錄中的Common Lisp代碼。

雖然可以根據論文編寫Python(或其他語言)解決方案,但作者列舉了印度日曆規則很好,所以如果您願意考慮使用提供的Common Lisp代碼。

+0

太棒了!我認爲在本文的幫助下,應該可以實現日曆轉換。 – Alp 2012-03-02 14:46:22

+0

需要注意的是,幾乎所有的實現 - 包括我發佈的Python中的一個以及您最初在您的問題中提到的那個實現都使用了來自該文章的Lisp片段的代碼。 – 2012-03-04 09:19:00

17

您是否檢查DateTime-Indic-0.1模塊系列?至少DateTime::Indic::Chandramana 似乎有將傳統日期轉換爲UTC值(utc_rd_values)的方法。

UPDATE:

我想Calendar::Saka可能是有用的,以及對於很多用戶來說(我知道,這是印度國家日曆),特別是to_gregorian()from_gregorian()方法。

+0

謝謝,我該如何安裝?我安裝了CPAN,現在試圖執行'perl Makefile.PL',但它會給出錯誤,例如'Warning:prerequisite DateTime :: Event :: Lunar 0.06 not found.' – 2012-02-25 11:57:49

+0

'cpan install DateTime :: Event :: Lunar 「告訴你,對不起? – raina77ow 2012-02-25 11:59:15

+0

缺少一些其他依賴關係。我正在嘗試安裝它們。 – 2012-02-25 12:05:27

5

似乎是一項艱鉅的任務。根據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日。所以,仍然存在一些轉換規則。也許你可以給我更多的信息,以便我可以更正上面的代碼。

11

對於Python,使用calendar2(注意:這不是內置的日曆模塊)。

使用示例:

>>> from calendar2 import * 
>>> old_hindu_solar_from_absolute(absolute_from_gregorian(3,1,2012)) 
(11, 16, 5112) 
>>> old_hindu_lunar_from_absolute(absolute_from_gregorian(3,1,2012)) 
(12, 0, 8, 5112) 
1

我不知道這是否是正確的做法或沒有,但 請到http://calendarhome.com/converter/網站和下載兩個JavaScript文件astro.js和calendar.js並按照公曆日期平變化事件,並獲取印度民用日期參數。