• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need a java Date Function

 
bob morkos
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to create a java date function as the following:
mmddyyyy (09212001). Thanks.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you check out the SimpleDateFormat class?
http://java.sun.com/j2se/1.3/docs/api/java/text/SimpleDateFormat.html
------------------
Sun Certified Programmer for the Java� 2 Platform
 
kb kb
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hope this solves your problem
it takes in a string validates if it is a valid date and retuns a string int the reverse order
like you should give
java DateValidation 23-4-2001
just try out and see
import java.util.*;
import java.text.*;
public class DateValidation
{

private String datestring= null;

public DateValidation(String testStr)
{
boolean error = false;
DateFormat formatter = new SimpleDateFormat( "dd-MM-yyyy" );
formatter.setLenient(false);
Date date = null;
if (testStr.length() != 0)
{
try
{
date = formatter.parse(testStr);
SimpleDateFormat formatter1= new SimpleDateFormat ("yyyy/MM/dd");
formatter1.setLenient(false);
datestring=formatter1.format(date);
}
catch (ParseException ex)
{

System.out.println("Error parsing date");
}
}

}
public String getDateString()
{
return this.datestring;
}
public static void main(String a[])
{
DateValidation dv = new DateValidation(a[0]);
System.out.println(dv.getDateString());

}
}
 
bob morkos
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, thanks a lot for your help. I love this date formater, it's so easy to use and you don't know how much you help me.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!