5 Replies - 1284 Views - Last Post: 09 June 2014 - 07:27 AM Rate Topic: -----

#1 Intern2014  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 03-June 14

Setting todays date as default with JDatePicker

Posted 06 June 2014 - 04:31 AM

Hi

I have a simple form that utilises JDatepicker to select a date. Its for selecting todays date so makes sense to have the dafault as todays date. However it will change sometimes for editing so i need it changeable rather than just force todays date at all times.

When i launch the GUI, the textfield for the JDatePicker is blank and id like it to be todays date.

this is the code which sets the default date but is there any way to make that dynamic and change everyday

UtilDateModel model = new UtilDateModel();
model.setDate(1990, 8, 24);

Is This A Good Question/Topic? 0
  • +

Replies To: Setting todays date as default with JDatePicker

#2 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Setting todays date as default with JDatePicker

Posted 06 June 2014 - 04:46 AM

You can use calendar class to get date:
Calendar today = Calendar.getInstance();
System.out.println(today.getTime());

Was This Post Helpful? 1
  • +
  • -

#3 CasiOo  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1413
  • View blog
  • Posts: 3,135
  • Joined: 05-April 11

Re: Setting todays date as default with JDatePicker

Posted 06 June 2014 - 05:22 AM

Or LocalDate if you're using Java 8
LocalDate now = LocalDate.now();
model.setDate(now.getYear(), now.getMonth(), now.getDayOfMonth()); 



I like Java 8 :D
Was This Post Helpful? 1
  • +
  • -

#4 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 856
  • View blog
  • Posts: 2,620
  • Joined: 29-July 11

Re: Setting todays date as default with JDatePicker

Posted 06 June 2014 - 06:43 AM

Yes, we should all be using Java8, but the OP should be using the DatePicker in Javafx.
Was This Post Helpful? 0
  • +
  • -

#5 Intern2014  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 03-June 14

Re: Setting todays date as default with JDatePicker

Posted 09 June 2014 - 07:25 AM

Hi

Im trying to figure out how to get todays date as 3 variables

i.e
int year = 2014;
int month = 06;
int day = 09;

Its to use in setting the default selection for a date picker.
Id like it to change everyday.

How do i grab todays date in String format YYYY-MM-DD then split it into 3 seperate ints?

Thanks in advance.

Edit -

   Date date = new Date();
		String modifiedDate= new SimpleDateFormat("yyyy-MM-dd").format(date);
		System.out.println(modifiedDate);


Auto importing imported sql.date rather than util.date which was messing it up.
Was This Post Helpful? 0
  • +
  • -

#6 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: Setting todays date as default with JDatePicker

Posted 09 June 2014 - 07:27 AM

*Topic Merged*
You have been given examples of this in your previous thread. Check the previous posts.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1