1 Replies - 638 Views - Last Post: 05 May 2012 - 10:00 AM Rate Topic: -----

#1 Chario0z  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 23-April 12

Date and Time

Posted 05 May 2012 - 04:40 AM

Hello again,

This time, I want to create a simple function where you choose a date with JSpinner, and next to it, I want a textfield where you can enter the time.
I've already created a JSpinner with both date and time, but it kind of looks bad, but that's my opinion. Also, whenever I run my app, it gives me my local time, and date, which is very nice, but kind of "bad".

I want to register some movies, and I want to select a date for it, and insert the time by myself. It's kinda "hard" to scroll it with the JSpinner.

I tried this out, and I did it. But the thing is, I've got some other classes which requires the date in this format:
"YYYY-mm-dd HH-mm-ss" - I can do this with my spinner

But when I try:

dateSpinner.getValue().toString() + " " + timeField.getText(); 

timeField.getText() = 20:00:00

My output becomes:
2012-05-04 00:00:00 CET 20:00:00.

This isn't the format that I want. I've tried using SimpleDateFormat, but the thing is that I can't get my JSpinner output to be "YYYY-mm-DD".

How can I do this? How can I get my JSpinner Output to be "YYYY-mm-DD"?

Right now, this is how I've created my dateSpinner.

datoSpinner = new JSpinner(new SpinnerDateModel());
        datoSpinner.setEditor(new DateEditor(datoSpinner, "yyyy-MM-dd HH:mm:ss"));

Also, one more question. How can I set a limit to my JSpinner? I don't want my Jspinner to go under today, this times limit.
For example, if I open my JSpinner, and it's 2012-05-04 22:44:13,
I don't want it to go lower than 2012-05-04 22:44:13.


Is This A Good Question/Topic? 0
  • +

Replies To: Date and Time

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Date and Time

Posted 05 May 2012 - 10:00 AM

Use a java.sql.Date it does not have a time field and its toString() method returns YYYY-MM-DD
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1