The Ancient Egyptians were the first to create a 365 day calendar. They did it because they needed to come up with a method of knowing when the Nile would flood every year, as it seemed to flood regularly.
Likewise, agriculture was regulated by the rise and fall of the Nile, and for a long time the lunar months were used to measure shorter periods of time. The Nile, however, was erratic and the intervals between floods showed considerable variation. Also, a year of lunar months didn't always coincide with the Nile year. A better method had to be devised.
The state also needed more precise records. This was done first by the invention of writing and by having scribes record events as they occurred. This also allowed for one generation to communicate with the next so information obtained would not be lost. It also allowed for better methods of recording time so that events could be predicted.
Over time, as such scribes recorded and took notes, records, of the number of days between Nile flooding, it must have been noted that the average was close to 365 days. A year of 365 days was established.
Ultimately it must have been observed this was not accurate over time. The scribes would predict the flood and it would be off by a day or two. They realized the year was actually 365 1/4 days long. The Roman calendar is based on the Egyptian 365 day calender. But at the time of the Ancient Romans, when Julius Caesar was king, the calendar was changed in 45 B.C. to account for the extra 1/4 days.
The Egyptian year consisted of 12 months of 30 days each and 5 additional days at the end of the year. The Babylonians also had a calendar based on lunar activity. The Greeks also had a lunar calendar, but they added days based on events. So these older calendars weren't always so accurate. It became a very complicated task to calculate the number of days between two given Babylonian or Greek new year's days, say, 50 years apart.
In Egypt the number is simply 50 times 365. For this reason the Egyptian calendar continued to be used used through the Middle ages and was still used by Copernicus in his lunar and planetary tables.
The division of the day into 24 hours, the day into ten, with one hour at each end for twilight; this gave a total of 24 hours of unequal length. Later (by 1300 B.C.), the concept of 24 hour equal hours developed and later adopted by the Greek astronomers. In Greco-Roman world, however, the civil hours continued to be of unequal length because they were reckoned as being on-twelfth of the day and night respectively. Therefore, our present division of the day into 24 hours of 60 minutes each is the result of a Hellenistic modification of an Egyptian practice.
The Ancient Sumerians and Babylonians had a numerical system based on the number six, and this is where we get 60 minutes in an hour, and 60 seconds in a minute. It's also where we get 180 degrees and the 360 degree circle.
So it is easily apparent that an accurate measurement of time was needed in order to keep accurate records and to predict when the rivers would flood. It was important to know the time of year to plant crops and harvest them. Thus developed the need for creating a length of day and year. Although complicated, the system developed to what we currently use over a period of thousands of years.
Of course we owe it all to the creation of a method of writing and record keeping.