| Author |
Formatting date with older java version
|
Colm Dickson
Ranch Hand
Joined: Apr 04, 2009
Posts: 84
|
|
Hello all,
I'm working with a database that is only running Java version 1.1 so it does not have access to any of the new date classes such as DateFormat etc...
I want to parse strings to get out date values so the only way I see of doing it on this version is by using Date.parse() as follows
Date d = new Date(Date.parse(st.nextToken()));
but my date is formatted like the following
Mon Sep 01 00:00:00 GMT 2009
What do I need to do, using this version, so that my dates are represented like '01/09/2009' or simply '01-SEP-2009'?
Also, if I pass in a date like '05/06/09' it reads it in as the first 2 figures being the month and not the year. How do I correct this?
Thanks,
Colm
|
 |
Colm Dickson
Ranch Hand
Joined: Apr 04, 2009
Posts: 84
|
|
To expand on my first question question...I have found a way to format the date as a string they way I want as follows
System.out.println(String.format("%td/%<tm/%<ty", new Date()));
However, is there a way to create and store the date reference in this format, so that if I have an arrayList of dates that they can be stored that way?
Thanks,
Colm
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
Something doesn't make sense here. If you can use "String.format(...)" then you're using at least Java 1.5, as that's when the format() method was first added to Java. Not to mention the fact that DateFormat and SimpleDateFormat have been in Java since it was first produced, so there's no reason you can't use them in any Java program at all.
And when you refer to a "database running Java version 1.1" exactly what does that mean? Most databases don't run Java in any way at all. Could you give us some more details about that, like the name of the database?
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12924
|
|
Paul Clapham wrote:And when you refer to a "database running Java version 1.1" exactly what does that mean? Most databases don't run Java in any way at all.
Oracle has a JVM running in the database, you can even write your stored procedures in Java instead of PL/SQL. But if it's only Java 1.1, then you must be using a really old version of Oracle.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Colm Dickson
Ranch Hand
Joined: Apr 04, 2009
Posts: 84
|
|
Hi again.
Sorry, I cannot use String.format... I was trying String.format in my latest version of Java.
What I need is something like that but for version 1.1 and yes, I am using Oracle 8 and that is why I only have 1.1 at my disposal. I've loaded in a java class and I want to perform some date formatting in its static method.
Thanks,
Colm.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32678
|
|
|
You can try things like DecimalFormat, but I would think you are better off getting rid of the Java1.1.
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
Campbell Ritchie wrote:I would think you are better off getting rid of the Java1.1.
And the Oracle 8 as well. It was released in 1997 and even the current version (Oracle 11) is two years old.
|
 |
 |
|
|
subject: Formatting date with older java version
|
|
|