×
The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.
I would think you should be able to use the SimpleDateFormat then to format
the date.
Probably not the most elegant, but...
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;
import java.text.SimpleDateFormat;
public class TestStringDate {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
int month = 0;
int day = 0;
int year = 0;
String stringDate = "11/4/2008";
Scanner scanner = new Scanner(stringDate);
scanner.useDelimiter("/");
int part = 0;
while (scanner.hasNext()) {
part++;
if (part > 3)
break;
if (scanner.hasNextInt()) {
switch (part) {
case 1:
month = scanner.nextInt() - 1;
break;
case 2:
day = scanner.nextInt();
break;
case 3:
year = scanner.nextInt();
break;
}
continue;
}
}
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
Calendar cal = new GregorianCalendar(year, month, day);
String s = sdf.format(cal.getTime());
System.out.println(s);
}
}
This will at least give you a string in the format you need.
James R. Perkins
On Wed, Nov 5, 2008 at 2:36 PM, <TAllen@xxxxxxxxxxxx> wrote:
I agree (again) that using strings is not ideal. Your guess is more or
less accurate. I'm using a set of classes for database access that does
not currently provide for SQL date objects.
Thanks,
Todd
As an Amazon Associate we earn from qualifying purchases.