How do I get the current date and time in Java?
I am looking for something that is equivalent to DateTime.Now from C#.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Just construct a new
Dateobject without any arguments; this will assign the current date and time to the new object.In the words of the Javadocs for the zero-argument constructor:
Make sure you’re using
java.util.Dateand notjava.sql.Date— the latter doesn’t have a zero-arg constructor, and has somewhat different semantics that are the topic of an entirely different conversation. 🙂