• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1283
  • Last Modified:

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

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

thanks
0
ursreenu
Asked:
ursreenu
  • 4
  • 3
1 Solution
 
CEHJCommented:
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
 
objectsCommented:
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
 
objectsCommented:
> 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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
CEHJCommented:
>>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
 
CEHJCommented:
If you want UTC in your target format, set the TimeZone on that DateFormat:
d2.setTimeZone(TimeZone.getTimeZone("UTC"));

Open in new window

0
 
CEHJCommented:
ursreenu, can you explain why you accepted an answer that is just a copy of mine?
0
 
objectsCommented:
Let me know if you need any further help :)

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now