Melatonin is commonly taken one to two hours before bedtime. This is because melatonin is a hormone that the body naturally produces at night to prepare for sleep, so taking a supplement can enhance this natural process.