Solved

Convert Datetime(yyy-MM-dd'T'hh:mm:ss) to date(mm/dd/yy) in java

Posted on 2009-05-06
7
1,231 Views
Last Modified: 2013-11-23
Hi
i need to  Convert Datetime(yyy-MM-dd'T'hh:mm:ss) to date(mm/dd/yy) in java

thanks
0
Comment
Question by:ursreenu
  • 4
  • 3
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 24312772
Try
String d = new SimpleDateFormat("MM/dd/yy").format(new SimpleDateFormat("yyy-MM-dd'T'hh:mm:ss").parse(date));

Open in new window

0
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 24312781
parse the date (using source format)

http://helpdesk.objects.com.au/java/how-do-i-parse-a-java-string-that-specifies-a-date

then format it (using the target format)

http://helpdesk.objects.com.au/java/how-do-i-format-a-date-as-a-string

let me know if you need my help

0
 
LVL 92

Expert Comment

by:objects
ID: 24312788
> String d = new SimpleDateFormat("MM/dd/yy").format(new SimpleDateFormat("yyy-MM-dd'T'hh:mm:ss").parse(date));

just as i suggested :) though I wouldn't do it in one line. you'll get poor performance with that. Instead create two DateFormat's and reuse them

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 86

Expert Comment

by:CEHJ
ID: 24312822
>>parse the date (using source format)

Just as i suggested. ursreenu, i assume you know how to save instances of classes if you want to to reuse them ;-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24312844
If you want UTC in your target format, set the TimeZone on that DateFormat:
d2.setTimeZone(TimeZone.getTimeZone("UTC"));

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24313294
ursreenu, can you explain why you accepted an answer that is just a copy of mine?
0
 
LVL 92

Expert Comment

by:objects
ID: 24313335
Let me know if you need any further help :)

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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 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…

776 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