This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Date(long date)

 
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
 
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().
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • 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
 
"The Hood"
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
 
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.
 
My previous laptop never exploded like that. Read this tiny ad while I sweep up the shards.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!