Solved

Need to reformat a date coming in to another format

Posted on 2001-08-15
4
217 Views
Last Modified: 2011-09-20
I have a string coming in that is actually a date that has this format MM/dd/yyyy hh:mm:ss. I want to take this date and reformat it so it looks like this dd-MMM-yyyy and the key here is I need to return the data back as a string again not a Date() object. I was playing around with simpleDate format but can't get it to work. please help....
0
Comment
Question by:npanarella
4 Comments
 
LVL 4

Accepted Solution

by:
antons061400 earned 50 total points
ID: 6389208
SimpleDateFormat f = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
Date date = f.parse("11/02/2000 13:34:45");
SimpleDateFormat ff = new SimpleDateFormat("dd-MMM-yyyy");
String newstr = ff.format(date);

0
 

Expert Comment

by:ksalman
ID: 6391217
I did the following code

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.*;


public class Test
{
     public static void main(String args[])
     {
     SimpleDateFormat f = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
     Date date = f.parse("11/02/2000 13:34:45");
     System.out.println("F = " + date );
     SimpleDateFormat ff = new SimpleDateFormat("dd-MMM-yyyy");
     String newstr = ff.format(date);
     System.out.println("n = " + newstr );
      }
}


This printed the values as below:

F = Thu Nov 02 13:34:45 EST 2000
n = 02-Nov-2000

I do not understand, what else did you need?

Let me know if you need any more clarification.


0
 

Expert Comment

by:lawpan
ID: 6391750
ksalman, why are you answering? The answer is right above.
In here people gives hints how to solve problems, not doing the work for them. Anton gave the clear answer. You dont have to copy his code and fill out the rest of the code.
Its quite obvious.
0
 

Expert Comment

by:SpideyMod
ID: 8289645
Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
couple of eclipse 5 36
how to add new optional parameter to JSP 1 40
expectj telnet failing 5 35
type mismatch (Object[] to double[] 4 24
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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 will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

776 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