In general, the answer to this is yes. Assuming that the item that was taken from you is something that is against school rules, or that could be seen as a disruption to the learning environment, then the teacher can certainly take it away from you. The length of time that they can keep it is generally stated in school rules, but the rule of thumb is that they can keep it for some reasonable amount of time.
Students in schools do not have the same rights as people who are out in public. The purpose of a school is to educate students and courts have held that schools have the right to do things to protect their ability to fulfill their purpose even if those things would not be legal outside of the school setting. For example, you would be within your rights to wear a hat in public, but your school could take it away from you if it has a rule against hats.
As far as how long the teacher can keep your item, you should start by looking at the school rules. The rules will often state when a confiscated item will be returned. At any rate, keeping an item overnight will almost always be seen as a reasonable punishment when a student breaks the rules by having that item at school.
The answer to your question has not actually been reviewed by the Supreme Court, but is largely held by a decision made in Arkansas called Koch v. Adams. In the case a young man had his phone seized for two weeks where in the school refused to give him the SIM card.
The student sued the school claiming that the confiscation violated his rights and at the very least they should have given him the SIM card to protect his right to privacy.
The ruling enforced the importance of school documentation and maintaining a paper trail. Because the school had a clear policy that had been explained to the student and the student's parents; because the student had signed a contract specifically outlining the consequences of phone usage at the school; and because the school did not search the student's phone, the school's right was upheld to follow policy and confiscate the phone according to the rules set by the school.
Because of this particular ruling, schools are responsible for informing students and parents of the rules, keeping documentation of warnings and parent conferences that try to solve the problem, and their reasoning for the confiscation. If they follow these guidelines, they can keep the items for as long as the consequence policy stipulates.