?
Solved

Date is not coming correctlty

Posted on 2007-04-08
4
Medium Priority
?
177 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
[X]
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
  • 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 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

771 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