aspose file tools*
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 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "System time" Watch "System time" New topic
Author

System time

Mary Taylor
Ranch Hand

Joined: Sep 11, 2000
Posts: 319
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.
Thanks.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Date rightNow = new Date();
or
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
Sheriff

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: http://aspose.com/file-tools
 
subject: System time
 
Similar Threads
Elco Teq, Bangalore - Contact
time estimation - part of architect's job
CORBA bad operation error in RI
Socket stream get stuck?
What do you think of this site`