Converting to and from the Hindu calendar

How can I convert unix time to hindu calendar & shy; Wikipedia and vice versa: php , Perl or Python or Java ? I know that I can convert to Hebrew and Jewish . But Hindu not an option.

To be more specific, I'm talking about the Hindu lunar calendar. The following website works and does exactly what I want: http://web.meson.org/calendars/ . For example, he “translates” 28-1-2012 (Gregorian) to 5-11-2068 (Hind. Lun.). How can I accomplish the same task? And if there are absolutely no scripts, how can I write it myself?

+43
java python php perl calendar
Dec 27 '11 at 2:53 on
source share
5 answers

Paper: Indian Calendar Calculations
Provides generic Lisp code in an application.

While a Python (or other language) solution can be written according to the document, the authors list the calendar rules in India very well, so this is pretty solid paper if you want to consider providing the Common Lisp code provided.

+8
Mar 02 '12 at 10:13
source share

Have you checked the DateTime-Indic-0.1 family of modules? At least DateTime :: Indic :: Chandramana seems to have a method of converting a traditional date to UTC values ​​(utc_rd_values).

UPDATE:

I believe Calendar :: Saka can also be useful for many users (as I already knew, this is the Indian national calendar), in particular, to_gregorian() and from_gregorian() .

+17
Feb 25 2018-12-12T00:
source share

For Python, use calendar2 (note: this is not a built-in calendar module).

Using an example:

 >>> 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) 
+11
Mar 01 '12 at 7:00
source share

This seems to be a difficult task. According to this discussion on bytes.com there is no clear way to perform a 100% correct conversion. But it seems that they are mistaken in believing that the Hindu calendar has only 364 days instead of 365 (or 366 in leap years).

You can find a good conversion table here, including leap year processing: http://hinduism.about.com/od/basics/a/monthsdayseras.htm

If it is as simple as written there, you can try something like this (php code):

 <?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("dmY", mktime(11, 59, 0, $newMonth, $newDay, $newYear)); } function dateIsLeapYear($date) { return date('L', strtotime($date)); } $date = date("dmY", strtotime('2012-01-28')); echo 'Date: ', $date, ' (is leap year: ', dateIsLeapYear($date) ? 'yes' : 'no', ')<br />'; echo 'Converted Hindu date: ', convertDateToHinduDate($date); ?> 

The output of this code is:

 Date: 28-01-2012 (is leap year: yes) Converted Hindu date: 07-11-2068 

But according to the calculator this Java applet , it should be 05-11-2068 instead of 07-11-2068. So there are still some conversion rules. Perhaps you can give me more information so that I can fix the code above.

+5
Feb 25 2018-12-12T00:
source share

I don’t know if this approach is right or not, but go to http://calendarhome.com/converter/ and download two javascript files astro.js and calendar.js and follow the events according to the Gregorian date and get the Indian Civil Date parameters .

+1
Mar 03 '12 at 5:19
source share



All Articles