A number of ancient civilizations had devised methods to predict exact dates and times of such eclipses, marking them as important events. Hence I assume the predictions were based on calculations, which should be quite easy to do now. So what is the exact formula to predict the exact date and time(this is optional, but desirable) of lunar and solar eclipses? Also how to calculate if the solar eclipse will be visible from a particular location or not?
The NASA sites have some very useful resources for this I will list them below:
There is more than one formula depending on which time frame you are trying to look in.
This is the formula for eclipses between the year 2005 and 2050:
This Link has an index like above but for all of the solar eclipses from -1999 to +3000.
This link has the formula for calculating solar eclipses. This is the formula for between 2005 and 2050:
Calculation of solar eclipses can be done using Besselian elements. The basic idea is to compute the motion of the Moon's shadow on a plane that crosses the Earth's center. Then, the shadow cone of the Moon can be projected on the Earth surface. The Besselian elements are the following:
what you have to do now is to compute the variation of these parameters, which are time-dependent. It happens that it can be done using polynomial expensions for a given reference time $t_0$. The polynomial expension is of the form, for a Besselian element a:
$$a = a_0 + a_1*t + a_2*t^2 + a_3*t^3$$
(a third order expension is enough in general), with $t = t_1 - t_0$, $t_0$ being the Terrestrial Dynamical Time (TDT) to the nearest hour of the instant of greatest eclipse.