Creating a calendar that keeps exactly in time with the seasons and precisely matches the cycle of the sun and stars is mathematically impossible. The mean tropical year, which is the length of time required for the Sun to return to the same position in the heavens is, to seven decimal places, 365.2421897 days and can't be expressed exactly as a fraction, making it impractical to create a calendar with a cycle that exactly matches the mean tropical year. However, it's possible to get reasonably close.
The Julian calendar was instituted in 46 B.C. This calendar featured regular years of 365 days, with leap years, or bissextile years, every four years, so the average length of the year was 365.25 days. Thus, the Julian calendar would lose a day every 1⁄365.25 − 365.2421897 years, which works out to around 128 years. So, by 1581 the first day of spring, which fell on March 21 in the year 325, now fell on March 11. To fix the accumulated error, Pope Gregory XIII, in 1582, directed that the 5th through 14th of October of that year were to be suppressed, and changed the calendar such that years that were multiples of 100 but not 400 were to be regular years instead of leap years.
With this adjustment, the mean length of the year under the Gregorian calendar is 365.2425 days, resulting in an error of 1 day in around 3200 years or so. Perhaps this error could be mostly rectified by changing the calendar such that years divisible by 3200 are designated as regular years instead of leap years, but this isn't something that we need to worry about for another 1200 years or so.
The Gregorian calendar isn't the only calendar in the world, however. According to the Gregorian calendar, the new millennium arrived on January 1st, 2001. On that same date, in Buddhist Sri Lanka, the year was 2545. In India, the Indian calendar indicated the date of 6 Paush, 1922. The date according to the Muslim calendar was 5 Shawwal in the year 1421. In Israel, it was Tevet 6 in the year 5761. For the world's astronomers, it was Julian 2,451,910.
The Jewish calendar dates from what Jewish scholars believed the date of the creation to be. The starting point for the Buddhist calendar is the year of Buddha's death, generally believed to have occurred in 544 B.C. The Indian calendar, adopted in 1957, uses a starting point of 78 A.D., the first year of the reign of the semilegendary king Kaniska, who ruled over much of modern-day India. Muslims date their calendar from the Hegira—the flight of Mohammed from Mecca to Medina on Friday, July 16th, 622. Muslim years are based on twelve lunar months, so the 1,379 years between that year and 2001 correspond to 1,421 Muslim years.
In the 11th century, several Persian astronomers, including Omar Khayyam, created the Jalalai (also spelled Jalali or Jalaali) calendar. This calendar uses a system of irregularly intercalated days over a cycle of 128 years, and has a smaller error than the Gregorian calendar; the Gregorian calendar exceeds the solar year by about 26 seconds, while the Jalalai calendar loses about one second a year.
In the 16th century, Joseph Justus Scaliger, a scholar and physician, suggested that astronomers should use a cycle of 7,980 years. This number is the smallest number that is divisible by the numbers 15, 19, and 28. This fact is significant because 15-, 19-, and 28-year periods are often used in calculations of solar and lunar movements. (One use of the 19-year period) Scaliger took the start of one such cycle to be January 1st, 4713 B.C., when the celestial bodies were conveniently placed. It is believed he called this date "Julian" in order to commemorate his own father, Julius Caesar Scaliger.
If you're interested in calendars, you might also be interested in how to calculate the day of the week.