Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes Date(long date) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date(long date)" Watch "Date(long date)" New topic

Date(long date)

Jay X Brown
Ranch Hand

Joined: Jan 26, 2001
Posts: 51
i need a unique string that i can assign to filenames.
so, i'm trying to use the Date() class for this.
*** code fragment ***
Date what=new Date();
String thisMoment=String.valueOf(what);
this returns: Wed Mar 14 16:44:44 PST 2001
how do i get the milisecond portion of this. more generally, i guess this becomes a question of how to read the following javadoc.
*** from Java Documentation ***
public Date(long date)
Allocates a Date object and initializes it to represent the specified number of milliseconds since January 1, 1970, 00:00:00 GMT.
date - the milliseconds since January 1, 1970, 00:00:00 GMT.
thanks in advance.
ryan burgdorfer
Ranch Hand

Joined: Jan 24, 2001
Posts: 219
Use the getTime() method on your date object to return the number of milliseconds since January 1, 1970 (as a long).
You could then convert the long toString().

<UL TYPE=SQUARE><I><LI>Ryan Burgdorfer<BR><LI>Java Acolyte</I></UL>
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

You can also use :

Both of these are static methods, so you don't have to create a Date object. ( Unless you really want too... )

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Jay X Brown
Ranch Hand

Joined: Jan 26, 2001
Posts: 51
thanks guys!
but, while we're on the topic, how does one get all this from the javadocs of the type that i've quoted? any guide for reading javadocs?
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Well this is the JavaDoc homepage:
You might try getting a book like The Java Class Libraries
Part 2
Or The Core Java Foundation Classes:

"JavaRanch, where the deer and the Certified play" - David O'Meara
Connie Boyd
Ranch Hand

Joined: Feb 22, 2001
Posts: 73
Hi Jay!
You may be looking at old documentation. I checked out the documentation at the same link Cindy posted, and in addition to the documentation you posted above, there was a "See Also" section that pointed to System.currentTimeMillis().
Of course, it's just a ton of information to absorb, so I'm sure it just takes some time working with the classes.
I agree. Here's the link:
subject: Date(long date)
It's not a secret anymore!