Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

System time

 
Mary Taylor
Ranch Hand
Posts: 327
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Date rightNow = new Date();
or
Calendar rightNow = Calendar.getInstance();
 
Dana Hanna
Ranch Hand
Posts: 227
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and there's always the quick and dirty System.currentTimeMillis()
 
Frank Hale
Ranch Hand
Posts: 230
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also do this:
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic