Solved

Need to reformat a date coming in to another format

Posted on 2001-08-15
4
196 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
scoreUp challenge 14 47
Enhanced For loop vs ForEach Loop 4 54
noX challenge 17 75
network + 7 73
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…
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 learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now