File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "display current time" Watch "display current time" New topic

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


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: 14805

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 8 API documentation
I agree. Here's the link:
subject: display current time