• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Geting Current Time in Seconds?

 
Ranch Hand
Posts: 782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to get the curren time of the system in seconds.Plz help!.
Bye,
Viki.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about System.currentTimeMillis() and a little mathematics (such as / 1000)?
 
Vikrama Sanjeeva
Ranch Hand
Posts: 782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dirk,
I have tried the same before but got odd result.May be I am doing some silly mistake anywhere.Here is my code with o/p

O/P:1033139787
Bye,
Viki.
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You probably think it's odd because it returns the number of milliseconds since the epoch. From the api:


the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.

 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you are trying to get the seconds in the current minute of your system. e.g. If system time is 15:23:15, then you are trying to get 15. Is that what you're trying to do? If so, you need to check out the GregorianCalendar class
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here are two possible ways of getting the seconds in the current minute.
Use Calendar, eg:
Calendar calendar = Calendar.getInstance();
System.out.println("Seconds in current minute = " + calendar.get(Calendar.SECOND));
Or, use SimpleDateFormat:
SimpleDateFormat formatter = new SimpleDateFormat("ss");
System.out.println("Seconds in current minute = " + formatter.format(new Date()));
 
Time flies like an arrow. Fruit flies like a banana. Steve flies like a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic