This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
How many more date formatting???
Posted by Kishori Sharan on September 11, 2000 at 8:06 PM
Hi Here is a small program which does your date formatting the way you want. Thanx Kishori /////////////////////Test.java import java.util.* ; import java.text.* ;
public class Test { public static void main ( String[] args ) { // ParsePosition object is required to parse your date string "10.04/2000" ParsePosition pp = new ParsePosition ( 0 ) ; // This is your string ( which contains date ) String date = "10/04/2000" ; // Use the correct date format dd/MM/yyyy then only your date in string // "date" will be converted to a Date object correctly SimpleDateFormat df = new SimpleDateFormat ( "dd/MM/yyyy"); // First parse your date in string to a Date object using // correct format Date dt = df.parse ( date, pp ) ; // Change the format you want to display your Date object in df.applyPattern ( "dd MMM yyyy" ) ; System.out.println ( df.format ( dt ) ) ; } }
Replies:
|