I am trying to create a variable of type date from user input. I want it to be only a date, not time and other things in the variable, so I thought that parsing the input with DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); would accomplish that (according to the documentation, SHORT would be only a date dd-mm-yyyy). However, when I output the variable, I get the day, time and timezone, which I am not at all intrested in. Code that parses and saves variable Date Pn = df.parse(in.readLine()); How should I initialize the DateFormat?
Create another SimpleDateFormat instance with the format of how you want the output to look, and then call the ".format(...)" method and output the results.
Joined: May 05, 2000
You have to keep in mind that you are creating a Date object. The SimpleDateFormat used to load the data into the Date object has nothing to do with how the output of the Date object will look. As suggested, you can use the same or a different SimpleDateFormat object to format the Date for output.
Joined: Sep 09, 2003
Thank you very much, I didn't think of that the date could add it's own information