| Author |
Geting Current Time in Seconds?
|
Vikrama Sanjeeva
Ranch Hand
Joined: Sep 02, 2001
Posts: 756
|
|
Hi, I am trying to get the curren time of the system in seconds.Plz help!. Bye, Viki.
|
Count the flowers of your garden, NOT the leafs which falls away!
Prepare IBM Exam 340 by joining http://groups.yahoo.com/group/IBM340Exam/
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
|
How about System.currentTimeMillis() and a little mathematics (such as / 1000)?
|
[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
|
 |
Vikrama Sanjeeva
Ranch Hand
Joined: Sep 02, 2001
Posts: 756
|
|
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
Joined: Sep 13, 2002
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<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
|
 |
Blake Minghelli
Ranch Hand
Joined: Sep 13, 2002
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
Joined: Sep 27, 2002
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()));
|
- Dave
|
 |
 |
|
|
subject: Geting Current Time in Seconds?
|
|
|