• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Date(long date)

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic