Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Parsing a full date/time/timezone date to "yyyy-MM-dd"

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Parsing a full date/time/timezone date to "yyyy-MM-dd"

    When I use getDate() on my JDateChooser I get something like:

    Fri Nov 02 23:20:32 EST 2012

    I've tried using SimpleDateFormat but I can't figure out how to turn the above date into something like: "2012-11-02"

    I've tried using google to find the answer but couldn't find anything that solved this problem. The documentation for this JDateChooser is not clear on how to override what format the getDate() method spits out so I'm left with trying to parse what it gives me.

    This is the API of the JDateChooser I'm using: JDateChooser (JCalendar API)

    I'd appreciate it if anyone could clue me in on Date parsing.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Parsing a full date/time/timezone date to "yyyy-MM-dd"

    I've tried using SimpleDateFormat but I can't figure out how to turn the above date into something like: "2012-11-02"
    Post what you tried so we have a starting point.

    I've tried using google to find the answer but couldn't find anything that solved this problem.
    I promise the answer is there. Have you read the API you posted a link to? ...as in all of it?

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Parsing a full date/time/timezone date to "yyyy-MM-dd"

    Well you could use substrings, but that's more complicated than it needs to be. As the above post says, post your starting point at least.

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Parsing a full date/time/timezone date to "yyyy-MM-dd"

    Quote Originally Posted by Occidentally View Post
    When I use getDate() on my JDateChooser I get something like:

    Fri Nov 02 23:20:32 EST 2012
    No, to be precise that's not exactly what you get. What you are getting is a java.util.Date object, and what you're posting above is the value returned by this object's toString() method. It uses its own default DateFormatter to return this String value.

    I've tried using SimpleDateFormat but I can't figure out how to turn the above date into something like: "2012-11-02"
    SimpleDateFormat is definitely the way to go. I second all the recommendations above -- please show us what you've tried as you're probably just making a small mistake that is preventing you from achieving success. With a little nudge in the right direction, I'll bet that you'll solve this and gain a better understanding of how SimpleDateFormat works.

Similar Threads

  1. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM
  2. message box for error in parsing date
    By johnyjj2 in forum Exceptions
    Replies: 1
    Last Post: November 27th, 2011, 02:36 PM
  3. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  4. Problem parsing WHOIS date from text and capturing fields
    By jdev28 in forum Java Theory & Questions
    Replies: 5
    Last Post: July 16th, 2011, 03:27 PM
  5. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM

Tags for this Thread