Solved

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

Posted on 2009-05-06
7
1,241 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
[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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.

697 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