• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

display current time

 
Evan Pierce
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.currentTimeMillis()?

I have all my watches synchronized using it. Who needs days, months and years anyways?
 
Evan Pierce
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As stated in the Javadoc, System.currentTimeMillis() returns the elapsed time since midnight, January 1, 1970 UTC.
 
Ricky Martaputra
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15482
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic