Solved

Need to reformat a date coming in to another format

Posted on 2001-08-15
4
236 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 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

734 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