This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Java in General and the fly likes display current time Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "display current time" Watch "display current time" New topic
Author

display current time

Evan Pierce
Ranch Hand

Joined: Jan 31, 2006
Posts: 36
is there a way to get the current time that the computer my app is running on says? i tried looking into Date but it wouldnt just simply give me the time.
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4967

System.currentTimeMillis()?

I have all my watches synchronized using it. Who needs days, months and years anyways?


Author of Hibernate Made Easy, What is WebSphere???, JSF 2.0 Made Easy and the SCJA Certification Guides
Evan Pierce
Ranch Hand

Joined: Jan 31, 2006
Posts: 36
is this giving me the current time in milliseconds? im trying to get something like 11:20pm. there are 3,600,000 milliseconds in an hour and right now my clock says 11:20 which would mean this code should be giving me 40,000,000 but it is giving me a number much bigger then that.
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
As stated in the Javadoc, System.currentTimeMillis() returns the elapsed time since midnight, January 1, 1970 UTC.
Ricky Martaputra
Ranch Hand

Joined: Apr 04, 2005
Posts: 42
?
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12953
    
    3

You get a Date object that represents the current date and time simply by creating a Date object using the no-args constructor. You use a class like java.text.SimpleDateFormat to format it into a String anyway you like.

Lookup the class java.text.SimpleDateFormat in the API documentation.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: display current time
 
Similar Threads
How to get the current time in java?
How do demo softwares expire?
WA #1.....word association
SCWCD exam voucher
Java Timer issue