my dog learned polymorphism*
The moose likes Java in General and the fly likes display current time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
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: 4968
    
    1

System.currentTimeMillis()?

I have all my watches synchronized using it. Who needs days, months and years anyways?
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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

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://aspose.com/file-tools
 
subject: display current time
 
Similar Threads
WA #1.....word association
SCWCD exam voucher
Java Timer issue
How to get the current time in java?
How do demo softwares expire?