Detection of the temporal structure of stimuli is crucial for prediction. While perception of interval timing is relevant for immediate behavioral adaptations, it has scarcely been investigated, especially in invertebrates. Here, we examined whether the fruit fly, Drosophila melanogaster, can acquire rhythmic behavior in the range of seconds. To this end, we developed a novel temporal conditioning paradigm utilizing repeated electric shocks. Combined automatic behavioral annotation and time–frequency analysis revealed that behavioral rhythms continued after cessation of the shocks. Furthermore, we found that aging impaired interval timing. This study thus not only demonstrates the ability of insects to acquire behavioral rhythms of a few seconds, but highlights a life-course decline of temporal coordination, which is also common in mammals.