• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

System time  RSS feed

 
Ranch Hand
Posts: 327
  • 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.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Date rightNow = new Date();
or
Calendar rightNow = Calendar.getInstance();
 
Ranch Hand
Posts: 227
  • 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());
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and there's always the quick and dirty System.currentTimeMillis()
 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also do this:
 
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!