This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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 Java 8 in Action this week in the Java 8 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: 87
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: 87
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: 18155
    
    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: 13884
    
  10

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: 87
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: 36579
    
  16
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: 18155
    
    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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Formatting date with older java version
 
Similar Threads
values change unexpectedly due to threading issue?
problems with vss in cruisecontrol
IE 6 problem with Dates?
SimpleDateFormatter shows wrong hour?
add 10 days to currentDate in java.util.Date or cast to Calendar?