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: Date conversion in java..

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Date conversion in java..

    Hi,
    I want to convert a date which can be of any date formats into yyyy-mm-dd format...My code is below.Could anyone please tell what is wrong in it.
    String[] date_formats = {
    "MM/dd/yyyy",
    "dd/MM/yyyy"
    ,"dd-MM-yyyy",

    };

    String dateReceived = "13/11/2012";
    for (String formatString : date_formats){
    DateFormat userDate = new SimpleDateFormat(formatString);
    {
    DateFormat dateFormatNeeded = new SimpleDateFormat("yyyy-mm-dd");
    Date date = userDate.parse(dateReceived);
    String Dateconverted = dateFormatNeeded.format(date);
    System.out.println(Dateconverted);
    }


  2. #2
    Junior Member
    Join Date
    Jul 2014
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Date conversion in java..

    Hi there,

    For people to help it's useful if you put [ code=java] [ /code] (without spaces) around your code, and also paste the sample output.

    Thanks

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,113
    My Mood
    Mellow
    Thanks
    186
    Thanked 657 Times in 644 Posts

    Default Re: Date conversion in java..

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly using code or highlight tags per the above link.

    And how can we help you with what you're trying to do?

  4. The Following User Says Thank You to GregBrannon For This Useful Post:

    anamika s (August 4th, 2014)

  5. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,113
    My Mood
    Mellow
    Thanks
    186
    Thanked 657 Times in 644 Posts

    Default Re: Date conversion in java..

    Thread closed as a duplicate.

Similar Threads

  1. Splitting date string by date and time and assigning it to 2 variables
    By KaranSaxena in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 17th, 2014, 05:58 AM
  2. Start Date should be exactly 1 week before to End Date
    By bhanuchandar in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 26th, 2013, 07:07 AM
  3. Java Date Format in Date Object
    By Ashr Raza in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 13th, 2012, 09:47 AM
  4. Replies: 1
    Last Post: July 22nd, 2011, 07:08 AM
  5. JAVA to C++ conversion
    By hackerboy101 in forum Java Theory & Questions
    Replies: 1
    Last Post: April 28th, 2010, 08:31 PM