date formating

C

CaseT

Hi,

I'm new to Java so if this is the wrong group to post this question,
please point to the right group and TIA.

I need to reformat a datetime coming in via a variable.
If comes in the format of the following
2008-01-29 10:23:29.405

I need to reformat it to the following.
01/29/2008

I did search the web for Java date formating but didn't find anything
to help.
I hoping this might be an easy problem to solve for someone in this
group with a greater knowledge of Java than I.

I appreciate any help you might be able to offer.

Thanks again, Case
(e-mail address removed)
 
S

Stanimir Stamenkov

Tue, 29 Jan 2008 14:17:18 -0800 (PST), /CaseT/:
I'm new to Java so if this is the wrong group to post this question,
please point to the right group and TIA.

I think comp.lang.java.help is more appropriate. See also
"comp.lang.java.{help,programmer} - what they're for (mini-FAQ
2006-03-31)"
I need to reformat a datetime coming in via a variable.
If comes in the format of the following
2008-01-29 10:23:29.405

I need to reformat it to the following.
01/29/2008

Take a look at the java.text package and the "Formatting" [1]
chapter in the Java Tutorial.

DateFormat inputFormat =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
DateFormat outputFormat =
new SimpleDateFormat("MM/dd/yyyy");
String inputDate = "2008-01-29 10:23:29.405";
Date date = inputFormat.parse(inputDate);
String outputDate = outputFormat.format(date);

[1] http://java.sun.com/docs/books/tutorial/i18n/format/index.html
 
S

Stefan Ram

CaseT said:
2008-01-29 10:23:29.405
I need to reformat it to the following.
01/29/2008

public class Main
{ public static void main( final java.lang.String[] args )
{ java.lang.System.out.println
( "2008-01-29 10:23:29.405".replaceAll
( "^(\\d{4})-(\\d{2})-(\\d{2}).*", "$2/$3/$1" )); }}

01/29/2008
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top