Surgery with general anesthesia disturbs circadian rhythms, which may lead to postoperative sleep disorders and delirium in patients. However, it is unclear how circadian rhythms are affected by different anesthetics administered at different times during the rest-activity cycle. We hypothesized that pentobarbital (an agonist at the γ-aminobutyric acid A receptors) and ketamine (an antagonist at the N-methyl-d-aspartate receptors) would have differential effects on circadian rhythms, and these effects would also be influenced by the time of their administration (the active versus resting phase). Rats were divided into 4 groups according to the anesthetic administered (pentobarbital or ketamine) and the timing of intraperitoneal administration (active/night phase or resting/day phase). Using online pineal microdialysis, we analyzed pineal melatonin secretion and locomotor activity rhythms in rats under a light/dark (12/12-hour) cycle for 5 days after anesthesia and microdialysis catheter implantation. The data were analyzed for rhythmicity by cosinor analysis. Ketamine administered during the resting phase produced 65- and 153-minute phase advances, respectively, in melatonin secretion and locomotor activity rhythms on the first day after anesthesia. In contrast, ketamine administered during the active phase produced 43- and 235-minute phase delays. Pentobarbital had no effect on the phase of either melatonin secretion or locomotor activity, irrespective of the timing of administration. When administered during the active phase, both anesthetics decreased the amplitude of melatonin secretion on the day after anesthesia; when administered during the resting phase, however, neither anesthetic affected the amplitude. The amplitude of locomotor activity decreased in all animals for 3 days after anesthesia. Ketamine has opposite phase-shifting effects on circadian rhythms according to the time of administration, whereas pentobarbital has no effect. Furthermore, both anesthetics decrease the postoperative amplitude of pineal melatonin secretion if administered during the active, but not the resting, phase of the 24-hour rest-activity cycle.