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
Solved

Need to reformat a date coming in to another format

Posted on 2001-08-15
4
224 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet  URL Rewriting 1 42
javap bin 2 40
Detect Closed Loops (circles, figure-8s, etc) in PNG Images 6 56
Notify sent to other threads in Java 9 33
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

808 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