File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Formatting date with older java version

 
Colm Dickson
Ranch Hand
Posts: 89
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 89
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20166
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Colm Dickson
Ranch Hand
Posts: 89
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try things like DecimalFormat, but I would think you are better off getting rid of the Java1.1.
 
Paul Clapham
Sheriff
Pie
Posts: 20166
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic