Solved

Date is not coming correctlty

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

919 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

15 Experts available now in Live!

Get 1:1 Help Now