Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date(long date)

 
Jay X Brown
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jay X Brown
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Connie Boyd
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic