Please help me understand why the indefinite article is used in this case:
"I had a marvellous time!"
The word "time" can be a countable noun referring to a specific event. "In the time of Julius Caesar ..." means the time period when Julius Caesar was a live. "We had a marvelous time" means the event we were at was marvelous, like we went on a fun vacation or had a pleasant date or some such. "It was the best of times; it was the worst of times." There have been many times, i.e. many time periods, and this one was the best in some ways and the worst in others. Etc.
Sometimes the noun "time" could be countable when referring to a particular time period.