• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need a java Date Function

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to create a java date function as the following:
mmddyyyy (09212001). Thanks.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic