| 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
|
|
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
|
 |
 |
|
|
subject: display current time
|
|
|