For Programmers: Free Programming Magazines  


Home > Archive > Java Help > July 2006 > Convert Date from one format to another format









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Convert Date from one format to another format
lsrinu

2006-07-22, 4:01 am

Hi guys i am having one probem, my date object prints the in the
format Sat Oct 22 00:00:00 IST 2005 i want to convert this into
mm/dd/yyyy format, but the result must be the date object can anyone
please help, We will get the string useing SimpleDateFormatter
class. but i need only date object

Matt Humphrey

2006-07-22, 8:00 am


"lsrinu" <lellasrinu@gmail.com> wrote in message
news:1153547975.217074.206530@p79g2000cwp.googlegroups.com...
> Hi guys i am having one probem, my date object prints the in the
> format Sat Oct 22 00:00:00 IST 2005 i want to convert this into
> mm/dd/yyyy format, but the result must be the date object can anyone
> please help, We will get the string useing SimpleDateFormatter
> class. but i need only date object


Date objects are pure timestamps and are fully independent of any
formatting. You seem to say that you already have a date object--just
convert it to a string using a different SimpleDateFormatter, as in

Date d = .... // Whereever you got your date from
SimpleDateFormat outFormat = new SimpleDateFormat ("MM/dd/yyyy");
String s = outFormat.format (d);

If you have a string in the format and you're trying to produce a date
object, parse it with different formatter
SimpleDateFormat inFormat = new SimpleDateFormat ("EEE MMM dd hh:mm:ss zzz
yyyy");
Date d = inFormat.parse ("Sat Oct 22 00:00:00 IST 2005");

Cheers,
Matt Humphrey matth@ivizNOSPAM.com http://www.iviz.com/


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com