• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Gregorian-Hijri Dates Converter JAVA

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you have a question or are you just sharing your code ?
 
Ghaith Shamayleh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am just sharing the code
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, thanks then.

I do have some comments about the code. It contains a lot of "magic" numbers: 365.25, 4716, 30.6001, 1524, 2299160, 1867216.25, 36524.25, 122.1, 10631, 1948084, 1948085, 8.01, 28.5001, 29.5001, ...

What do all those numbers mean? How do you know this code works correctly? For which range of dates does it work correctly?
 
Ghaith Shamayleh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
These numbers are used to calculate the Islamic Higri date, you can check if the date returned on the following site if its correct
http://www.islamicity.com/PrayerTimes/defaultHijriConv.asp
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
365.25 in particular sounds suspicious - does this code handle leap years correctly in the long run?

Maybe you can provide a link to Wikipedia page or something like that where the topic (not necessarily the calculations) are explained.
 
Ghaith Shamayleh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://en.wikipedia.org/wiki/Islamic_calendar
http://en.wikipedia.org/wiki/Kuwaiti_algorithm
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very useful .. thank you
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ghaith shamayleh wrote:These numbers are used to calculate the Islamic Higri date, you can check if the date returned on the following site if its correct
http://www.islamicity.com/PrayerTimes/defaultHijriConv.asp


Then make them constants - private static final fields of the right type (int / double) with a descriptive name.
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The duration of a year is not 365.25 days. According to this webpage that is 11min 14 seconds too long. anyway, using floating-point arithmetic is bound to cause imprecisions.
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:The duration of a year is not 365.25 days. According to this webpage that is 11min 14 seconds too long. anyway, using floating-point arithmetic is bound to cause imprecisions.


It's much more complicated than that.

According to Wikipedia, a Julian year is 365.25 days. I guess that the definition on the above website is the length of a Gregorian year (a year according to the usual Gregorial calendar). But there are also other ways to define a year: for example a sidereal year, which is the time it takes the Earth to make exactly one orbit around the Sun, is slightly different (365 days, 6 hours 9 minutes, 9.7676 seconds). And there are other definitions which are again slightly different.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This code worked for me. But in my country its 25 rajab today and this code shows me 26 rajab. How can i change this please help me. Its so important for me. I have tried to change this by subtracting 1 but then it shows 0 as first day of month.Please help me
Thank you so much for your code.
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using Java 8 then you do not need this code - the new date and time API in Java 8 already supports the Arabic calendar. You can simply do this:

 
Ashna Ali
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using java with android and It does not supports this
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a library named Time4A which can do what you need. It's an advanced date and time library specifically for Android.

See also this post: How to display name Hijri month as a String using Joda-Time?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks its work in android studio
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SM: welcome to the Ranch
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic