Results 1 to 12 of 12
  1. #1
    ashin is offline Member
    Join Date
    Nov 2008
    Posts
    71
    Rep Power
    0

    Default Concatenate year from DATETIME

    hi guys so how can i concatenate year from dateTIme?

    DateTime dateFrom = new DateTime(parent, SWT.BORDER | SWT.DATE | SWT.DROP_DOWN);
    dateFrom.setDate(2007, 0, 1);

    thank you
    :cool:

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    ashin is offline Member
    Join Date
    Nov 2008
    Posts
    71
    Rep Power
    0

    Default

    I just want to concatenate the year.... example in DateTime we have 7/25/2010 , from this date i just want to get the year...

    thank you in advance..
    :cool:

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    SimpleDateFormat it all what you need. Look at the following code segment.

    Java Code:
      Date date = new Date();  // Set your date if different
      SimpleDateFormat simpleDateformat=new SimpleDateFormat("yyyy");
      System.out.println(simpleDateformat.format(date));

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Since the OP is using the extended by org.eclipse.swt.widgets.DateTime class and not the java.util.Date class, I'm not sure that SimpleDateFormat will work here. But according to the API for this class, there is a getYear() method that may work.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Of course not. I just point him on his last post, since that's the only thing he explain clearly. :)

  8. #8
    ashin is offline Member
    Join Date
    Nov 2008
    Posts
    71
    Rep Power
    0

    Default

    can you give me an example please.. thank you..
    :cool:

  9. #9
    ashin is offline Member
    Join Date
    Nov 2008
    Posts
    71
    Rep Power
    0

    Default

    thank you eranga.. but is it possible to get the years from 1980 to present then it will increase every year?
    :cool:

  10. #10
    ashin is offline Member
    Join Date
    Nov 2008
    Posts
    71
    Rep Power
    0

    Default

    Quote Originally Posted by ashin View Post
    thank you eranga.. but is it possible to get the years from 1980 to present then it will increase every year?
    What i mean as combo box?
    :cool:

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by ashin View Post
    can you give me an example please.. thank you..
    Relevant to what? Did you go through the code segment I've posted above in one of my previous post?

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by ashin View Post
    thank you eranga.. but is it possible to get the years from 1980 to present then it will increase every year?
    Do you want to find the difference between two dates, or just the difference between your years?

    Seems to me you have a selection field for the year and you know the starting year. So in that case where you stuck to find the difference? Even you refer them as years, for the VM those are just two integers (an year cannot be a double). Just deduct the largest from the smallest.

Similar Threads

  1. what is java free datetime picker
    By newbiejava in forum New To Java
    Replies: 5
    Last Post: 07-24-2010, 03:13 PM
  2. how to print the from and to datetime
    By baktha.thalapathy in forum New To Java
    Replies: 1
    Last Post: 06-10-2010, 09:58 AM
  3. Concatenate Linked Lists
    By tttestall in forum New To Java
    Replies: 1
    Last Post: 04-20-2010, 07:03 PM
  4. datetime on a jtextfield
    By devstarter in forum New To Java
    Replies: 1
    Last Post: 03-02-2010, 01:08 PM
  5. Date of first day, given the week in the year and the year...
    By Lee.J.Baxter in forum Advanced Java
    Replies: 1
    Last Post: 08-26-2009, 08:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •