Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3458270
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:57:43+00:00 2026-05-18T09:57:43+00:00

I would convert Gregorian date to Hijri (Islamic) date. After may search on the

  • 0

I would convert Gregorian date to Hijri (Islamic) date. After may search on the web, I found a source code to convert it.
I converted the code from Java and PHP to C base.

The implement some times working without any problem. But some days has problem.

I need your help either fix the implement or a available code that will work without any problem!
BTW I found another source code (http://emr.cs.iit.edu/~reingold/calendar.C) that is C++ base. As I don’t know C++ if anyone can convert that to C Base or Objective C would be prefect (still not sure this code will work correctly or not).

P.S. You can check the correct date in: islamicfinder.org/Hcal/index.php

void gregorian_to_hijri(int* h_y, int* h_m, int* h_d, int  g_y, int  g_m, int  g_d)
{
    int year, month, day;

    int zyr;
    int zd;
    int zm;
    int zy;

    float zjd;
    int zl;
    int zn;
    int zj;

    year = g_y;
    month = g_m;
    day = g_d;


    zyr = year;
    zd = day;
    zm = month;
    zy = zyr;

    if((zy > 1582) || ((zy == 1582) && (zm > 10)) || ((zy == 1582) && (zm == 10) && (zd > 14)))
    {
        zjd = ((1461 * (zy + 4800 + ((zm - 14) / 12))) / 4)
            + ((367 * (zm - 2 - 12 * (((zm - 14) / 12)))) / 12)
            - ((3 * (((zy + 4900 + ((zm - 14) / 12)) / 100))) / 4) + zd - 32075;
    }
    else
    {
        zjd = 367 * zy - ((7 * (zy + 5001 + ((zm - 9) / 7))) / 4)
            + ((275 * zm) / 9) + zd + 1729777;
    }

    zl = zjd - 1948440 + 10632;
    zn = ((zl - 1) / 10631);
    zl = zl - 10631 * zn + 354;
    zj = (((10985 - zl) / 5316)) * ((int)((50 * zl) / 17719))
        + ((zl / 5670)) * ((int)((43 * zl) / 15238));

    zl = zl - (((30 - zj) / 15)) * (((17719 * zj) / 50))
        - ((zj / 16)) * (((15238 * zj) / 43)) + 29;

    zm = ((24 * zl) / 709);
    zd = zl - ((709 * zm) / 24);
    zy = 30 * zn + zj - 30;

    *h_y = zy;
    *h_m = zm;
    *h_d = zd;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:57:44+00:00Added an answer on May 18, 2026 at 9:57 am

    Assuming this is for a Mac (Cocoa) or iOS (Cocoa Touch) app, since that’s where you see Objective C most often, then you can just do something like this:

    // Create a Gregorian Calendar
    NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    
    // Set up components of a Gregorian date
    NSDateComponents *gregorianComponents = [[NSDateComponents alloc] init];
    
    gregorianComponents.day = 4;
    gregorianComponents.month = 12;
    gregorianComponents.year = 2010;
    
    // Create the date
    NSDate *date = [gregorianCalendar dateFromComponents:gregorianComponents];
    
    [gregorianComponents release];
    [gregorianCalendar release];
    
    
    // Then create an Islamic calendar
    NSCalendar *hijriCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSIslamicCivilCalendar];
    
    // And grab those date components for the same date
    NSDateComponents *hijriComponents = [hijriCalendar components:(NSDayCalendarUnit | 
                                                                   NSMonthCalendarUnit |
                                                                   NSYearCalendarUnit)
                                                         fromDate:date];
    
    
    NSLog(@"[In Hijri calendar ->] Day: %ld, Month: %ld, Year:%ld", 
              [hijriComponents day],
              [hijriComponents month],
              [hijriComponents year]);
    
    [hijriCalendar release];
    

    If all you want is the current date, then you can skip setting up the gregorian date altogether and just do this:

    // Create an Islamic calendar
    NSCalendar *hijriCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSIslamicCalendar];
    
    // And grab the date components for the current date
    NSDateComponents *hijriComponents = [hijriCalendar components:(NSDayCalendarUnit | 
                                                                   NSMonthCalendarUnit |
                                                                   NSYearCalendarUnit)
                                                         fromDate:[NSDate date]];
    
    [hijriCalendar release];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From Sun's Java Tutorial , I would have thought this code would convert a
I'm currently writing some php code to convert dates from the Gregorian Calendar to
How would I convert the existing C# code _containerBuilder = new ContainerBuilder(); _containerBuilder.RegisterGeneric(typeof(CommandObserver<>)).As(typeof(ICommandObserver<>)); _containerBuilder.RegisterGeneric(typeof(PropertyProvider<>)).As(typeof(IPropertyProvider<>));
can anyone advise how i would convert a date like Tuesday, 22 June, 2010
I'm trying to write a code that would convert letters into numbers. For example
Does anyone know of a free-licence PHP code that would convert numbers to words
Anyone know how I would convert bytes which are sent via a websocket (from
Can someone please post a simple code that would convert, System::String^ To, C++ std::string
I'm trying to convert some code from C# to C so that it can
Hi I found this code on line and cannot convert it over to vb.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.