how to change the date time format in jsp
Hello Sir,
I am trying to convert the date from one format into another format.
In SQLServer one fields type as datetime.
when i tried to display it in jsp with String variable it shown like below,
2006-08-16 09:11:23.0
how to format this value as
Wed, Aug 16, 2006 09:11 AM
my code is
java.text.SimpleDateFormat fmt= new java.text.SimpleDateFormat("EEE, MMM d, yyyy K:mm a ");
fmt.format(string value fetch from dtabase field);
Plz provide me the solution asap. very urgent request.
Regards
venki.
> Hello Sir,
> I am trying to convert the date from one format into
> another format.
> In SQLServer one fields type as datetime.
> when i tried to display it in jsp with String
> variable it shown like below,
> 2006-08-16 09:11:23.0
>
> how to format this value as
> Wed, Aug 16, 2006 09:11 AM
> my code is
> java.text.SimpleDateFormat fmt= new
> java.text.SimpleDateFormat("EEE, MMM d, yyyy K:mm a
> ");
> fmt.format(string value fetch from dtabase field);
>
> Plz provide me the solution asap. very urgent
> request.
>
> Regards
> venki.
Have a look in to the below code
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateFormatTest
{
public static void main( String[] cmdArgs )
throws Exception
{
SimpleDateFormat sdfInput =
new SimpleDateFormat( "yyyy-MM-dd" );
SimpleDateFormat sdfOutput =
new SimpleDateFormat ( "EEE, d MMM yyyy hh:mm aaa" ); //Change the patterns in to what ever u need
String textDate = "2001-01-04";
Date date = sdfInput.parse( textDate );
System.out.println( sdfOutput.format( date ) );
}
}
i will suggest u to look in to the API doc you will come to know lot many things.
ragasa at 2007-7-14 21:27:29 >
