File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Formatting date with older java version Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Formatting date with older java version" Watch "Formatting date with older java version" New topic
Author

Formatting date with older java version

Colm Dickson
Ranch Hand

Joined: Apr 04, 2009
Posts: 89
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: 89
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: 18541
    
    8

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

Joined: Aug 16, 2005
Posts: 14074
    
  16

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: 89
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: 38075
    
  22
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: 18541
    
    8

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
 
Similar Threads
add 10 days to currentDate in java.util.Date or cast to Calendar?
IE 6 problem with Dates?
problems with vss in cruisecontrol
SimpleDateFormatter shows wrong hour?
values change unexpectedly due to threading issue?