-1

When I run my program, the default value is the actual time. Is there a way of setting the default value to "00:00"?

Date date = new Date();
morningtimeSpinner = new JSpinner(new SpinnerDateModel());  
morningtimeSpinner.setBorder(new LineBorder(Color.LIGHT_GRAY, 2, true));
morningtimeSpinner.setBounds(200,182,75,30);
contentPane.add(morningtimeSpinner);
JSpinner.DateEditor timeEditor = new JSpinner.DateEditor(
                                        morningtimeSpinner, "hh:mm a");
morningtimeSpinner.setEditor(timeEditor);
morningtimeSpinner.setValue(date);
morningtimeSpinner.addChangeListener(new ChangeListener() {
    @Override
    public void stateChanged(ChangeEvent arg0) {
        dd = (Date) morningtimeSpinner.getValue();
    }
});
Ken Y-N
  • 14,644
  • 21
  • 71
  • 114
  • 1
    1) Use a logical and consistent form of indenting code lines and blocks. The indentation is intended to make the flow of the code easier to follow! 2) Please use code formatting for code and code snippets, structured documents like HTML/XML or input/output. To do that, select the text and click the `{}` button at the top of the message posting editing form. – Andrew Thompson Oct 20 '14 at 05:16
  • this is a good question, don't understand downvotes – Khaled.K Oct 20 '14 at 05:29
  • @KhaledAKhunaifer Downvotes may be due to this question being addressed by hundreds of previous answers. Posting without bothering to search first is a waste of many people's time. – Basil Bourque Oct 20 '14 at 05:44
  • BTW `morningtimeSpinner.setBounds(200,182,75,30);` Java GUIs have to work on different OS', screen size, screen resolution etc. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). – Andrew Thompson Oct 20 '14 at 05:49

1 Answers1

2

Can be done as shown below using java.util.Calendar

// get calender for today's date    
Calendar date = new GregorianCalendar();

// reset hour, minutes, seconds and millis to midnight
date.set(Calendar.HOUR_OF_DAY, 0);
date.set(Calendar.MINUTE, 0);
date.set(Calendar.SECOND, 0);
date.set(Calendar.MILLISECOND, 0);

Alternatively, you can also use joda-time API

DateTime today = new DateTime().withTimeAtStartOfDay();
Shishir Kumar
  • 7,981
  • 3
  • 29
  • 45