File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes System time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "System time" Watch "System time" New topic

System time

Mary Taylor
Ranch Hand

Joined: Sep 11, 2000
Posts: 327
I've checked the SimpleDateFormat tutorial at Sun as well as the DateTime Tutorial. I am not seeing how one gets the time from the machine you are running on. I know it will be a "duh" as soon as someone points it out to me, but I'll have to live with that. I'm just not seeing it.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Date rightNow = new Date();
Calendar rightNow = Calendar.getInstance();

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Dana Hanna
Ranch Hand

Joined: Feb 28, 2003
Posts: 227
To be more specific:
Calendar cal = Calendar.getInstance();
int hour = cal.getField(Calendar.HOUR);
int minute = cal.getField(Calendar.MINUTE);
If you just want to have the time as a String:
SimpleDateFormat timeMaker = new SimpleDateFormat("hh:mm:ss");
//note that the default contructor of "Date" uses the current date/time
String time = timeMaker.format(new Date());
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
...and there's always the quick and dirty System.currentTimeMillis()

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
You could also do this:
I agree. Here's the link:
subject: System time
It's not a secret anymore!