That is similar to what I came up with:
String[] mdy = date.split("/");
java.text.SimpleDateFormat ymd = new
java.text.SimpleDateFormat("MM/dd/yyyy");
java.util.GregorianCalendar cal = new java.util.GregorianCalendar(
Integer.parseInt(mdy[2]), Integer.parseInt(mdy[0]),
Integer.parseInt(mdy[1]));
String dt = ymd.format(cal.getTime());
I did not want to hard-code the date format like that but at this point a
non-ideal solution is better than no solution.
Thanks,
Todd
"James Perkins"
<jrperkinsjr@gmai
l.com> To
Sent by: "Java Programming on and around the
java400-l-bounces iSeries / AS400"
@midrange.com <java400-l@xxxxxxxxxxxx>
cc
2008-11-05 18:07 Subject
Re: JDBC date insert
Please respond to
Java Programming
on and around the
iSeries / AS400
<java400-l@midran
ge.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
This communication and any transmitted documents are intended to be confidential. If there is a problem with this transmission, please contact the sender. If the reader of this message is not the intended recipient, or the employee or agent responsible to deliver it to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.
As an Amazon Associate we earn from qualifying purchases.