Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need to reformat a date coming in to another format

Posted on 2001-08-15
4
Medium Priority
?
243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 4

Accepted Solution

by:
antons061400 earned 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

670 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