How to calculate geocentric conjunction time and moon altitude at a given time Umm al-Qura calendar of Saudi Arabia determine the new moon if these criteria meet at 29th day:


The geocentric conjunction occurs before sunset.
The moon sets after the sun.


I've got the formula to calculate when the sun (seen by the observer) sets, considering observer's latitude, longitude, height (altitude from sea level), and the date (Julian Day). I would like to ask the formula to calculate:


When (the time) geocentric conjunction happens.
How much (the angle) the altitude of the moon (seen by the observer) at a given time is.


Thank you
I assume you have an algorithm to compute position of the Sun, since you can compute rise and set times.  You will need to compute the position of the Moon in a similar manner.  Then, convert both positions to geocentric ecliptical coordinates (ecliptic latitude and longitude) and use some numerical bisection method (root finder) to find where the difference of the longitudes of the two objects has a root (i.e., becomes zero).  The corresponding JD provides the moment of the geocentric conjunction.
Calculation of the altitude is a standard procedure - you'll need to convert your ecliptic coordinates to equatorial (right ascension and declination) and then to horizontal (azimuth and altitude).  Finally, correct for the horizontal parallax to convert your geocentric coordinates to topocentric coordinates for the location of the observer.