my dog learned polymorphism*
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
Author

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 ***
Date
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.
Parameters:
date - the milliseconds since January 1, 1970, 00:00:00 GMT.
****************
thanks in advance.
jay
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
Bartender

Joined: Oct 18, 2000
Posts: 4121

Jay,
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... )
HTH,
-Nate


-Nate
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?
thanks
jay
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Well this is the JavaDoc homepage:
http://java.sun.com/j2se/javadoc/index.html
You might try getting a book like The Java Class Libraries
http://www.amazon.com/exec/obidos/ASIN/0201310023/electricporkchop/107-9474481-6390958
Part 2 http://www.amazon.com/exec/obidos/ASIN/0201310031/electricporkchop/107-9474481-6390958
Or The Core Java Foundation Classes:
http://www.amazon.com/exec/obidos/ASIN/0130803014/electricporkchop/107-9474481-6390958

"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: http://aspose.com/file-tools
 
subject: Date(long date)
 
Similar Threads
Date 01/01/1970 returning non-zero value for time
compare dates for equality with a few minutes of "leniency"
Date type conflict...
convert timestamp to double
please help with an example