Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Date is not coming correctlty

Posted on 2007-04-08
4
174 Views
Last Modified: 2010-03-31
String x="2007/04/05";
            SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
            x= sdf.format(sdf.parse(x));
            System.out.println("DateExample.main().."+x);


            result:DateExample.main()..03/04/0172
0
Comment
Question by:chaitu chaitu
  • 2
4 Comments
 
LVL 10

Expert Comment

by:Jaax
ID: 18874467
Change the format to "mm/dd/yyyy"
0
 
LVL 2

Expert Comment

by:jhshen
ID: 18874481
Assume 04 is month and 05 is day.

String x="2007/04/05";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
x= sdf.format(sdf.parse(x));
System.out.println("DateExample.main().."+x);

result:DateExample.main()..2007/04/05
0
 
LVL 2

Accepted Solution

by:
jhshen earned 500 total points
ID: 18874486
Or maybe what you want to do is to convert 2007/04/05 to 04/05/2007.

Please refer to the code below:
String x = "2007/04/05";
        SimpleDateFormat sdf_from = new SimpleDateFormat("yyyy/MM/dd");
        SimpleDateFormat sdf_to = new SimpleDateFormat("MM/dd/yyyy");
        x = sdf_to.format(sdf_from.parse(x));
        System.out.println("DateExample.main().." + x);
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 18874523
Jaax,  'm' is for minutes, 'M' for months.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet example 11 49
eclipse console opening separately 2 29
Bot application - advice 3 38
Need Help! Getting a syntax error and don't understand why 3 31
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question