Both "the" and "an" work in this sentence. "the" implies that this is the single ideal time, while "an" implies that this is one of a number of ideal times. In practice, however, there is not a great difference in usage because there is no objective way to establish how many "ideal times" there actually are.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.