Click to See Complete Forum and Search --> : Convert date format - RESOLVED!!
rockies1
Jun 30th, 2003, 01:36 PM
I have a date that looks like this:
19721101
and I need it to be like this:
01-Nov-1972
How can I convert that?
Dillinger4
Jun 30th, 2003, 02:28 PM
import java.util.Date;
import java.text.DateFormat;
public class Z{
public static void main(String[] args){
Date d = new Date(19721101);
DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
System.out.println(df.format(d));
}
}
rockies1
Jul 1st, 2003, 03:24 PM
Before I had a chance to try this one, someone gave me this one:
public static String oracleDatePrep(java.util.Date dateIn)
{
SimpleDateFormat oracleDateFormatter = new SimpleDateFormat("dd-MMM-yyyy");
String returnVal = null;
if (dateIn != null)
{
returnVal = oracleDateFormatter.format(dateIn);
}
return returnVal;
}//End oraclePrep
public static java.util.Date parseToDate(String dateString)
{
if (dateString == null)
{
return null;
}
java.util.Date returnDate = null;
DateFormat formatter = new SimpleDateFormat("yyyyMMdd");
formatter.setLenient(false);
if (dateString.length() != 0)
{
try
{
returnDate = formatter.parse(dateString);
}
catch (ParseException pe)
{
}
}
return returnDate;
}//End parseToDate
that I call like oracleDatePrep(parseToDate("20030701"))
Thanks for your suggestions and help in the other threads!
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.