This week's book giveaway is in the Testing forum.We're giving away four copies of The Way of the Web Tester: A Beginner's Guide to Automating Tests and have Jonathan Rasmusson on-line!See this thread for details.
Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# Geting Current Time in Seconds?

Vikrama Sanjeeva
Ranch Hand
Posts: 760
Hi,
I am trying to get the curren time of the system in seconds.Plz help!.
Bye,
Viki.

Dirk Schreckmann
Sheriff
Posts: 7023
How about System.currentTimeMillis() and a little mathematics (such as / 1000)?

Vikrama Sanjeeva
Ranch Hand
Posts: 760
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.

Blake Minghelli
Ranch Hand
Posts: 331
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
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

David Hewitt
Greenhorn
Posts: 1
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()));