Solved

Date is not coming correctlty

Posted on 2007-04-08
4
172 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

707 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now