Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Date is not coming correctlty

Posted on 2007-04-08
4
Medium Priority
?
178 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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…
Suggested Courses

636 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