i need to parse a String value and get it as date object. Am using the following snippet
java.util.Date temp = new SimpleDateFormat("HH:mm:ss").parse("14:58:00");
My output is : Thu Jan 01 14:58:00 IST 1970
But what i need is only 14:58:00
as Date object is there any way to achieve this? If not what is the other way around? Please help.
EDIT I need this way because,
I have a Jspinner(in a Jpanel) for selecting time in HH:mm:ss format . The scenario is I will open the JPanel to select the time and click on save button so the values selected will be saved in a variable(x).Now if i open the Jpanel again the previously selected values should be shown which will be read from the variable(x).
For this am using following code,
SpinnerModel Startmodel = new SpinnerDateModel();
StarttimeSpinner = new JSpinner(Startmodel);
Date date = new SimpleDateFormat("HH:mm:ss").parse("14:58:00");
StarttimeSpinner.setValue(date);
On parse line am facing the problem. where i need only time(14:58:00) as date object.
NOTE: I have tried the below code( it will work but wont allow us to change value again)
StarttimeSpinner = new JSpinner();
Date time = new SimpleDateFormat("HHmmss", Locale.ENGLISH).parse("000000");
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
String dateString = formatter.format(time);
StarttimeSpinner.setModel(new SpinnerListModel(new String[]{dateString}));
您可能想使用new SimpleDateFormat("HH:mm:ss").formatDate(date)
(可以使用相同的new SimpleDateFormat("HH:mm:ss").formatDate(date)
实例)进行输出...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.