We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › milliseconds and tenths of seconds
Page Index Toggle Pages: 1
milliseconds and tenths of seconds (Read 764 times)
milliseconds and tenths of seconds
Nov 17th, 2008, 5:22pm
 


Hi, I need a little help if its not too much trouble.

Does anyone know how to get tenths of seconds and milliseconds out of processing?

I'm trying to make a clock that shows these values as well as hours, minutes and seconds.

If anyone can post a speedy reply to this I'd be very grateful.

Thanks

Si

Re: milliseconds and tenths of seconds
Reply #1 - Nov 17th, 2008, 8:03pm
 
"Does anyone know how to get tenths of seconds and milliseconds out of processing?"

> Are you looking for that granularity from the system clock? If so, you may want to check out System.currentTimeMillis() (http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#currentTimeMillis() ).
Hope this helps.
Re: milliseconds and tenths of seconds
Reply #2 - Nov 17th, 2008, 8:17pm
 
I'm trying to convert seconds to milliseconds somehow.

I basically want to make a clock that shows hours, minutes, seconds, tenths of seconds and thousands of seconds.
Re: milliseconds and tenths of seconds
Reply #3 - Nov 17th, 2008, 8:36pm
 
I guess the following shall do the trick:

Quote:
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS");

//
// Get date and time information in milliseconds
//
long now = System.currentTimeMillis();

//
// Create a calendar object that will convert the date and time value
// in milliseconds to date. We use the setTimeInMillis() method of the
// Calendar object.
//
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(now);

System.out.println(now + " = " + formatter.format(calendar.getTime()));



The formatter string basically would determine what part of the actual timestamp is output so if you don't need the actual date and just need the time, you can get rid of the dd/MM/yyyy part.
Re: milliseconds and tenths of seconds
Reply #4 - Nov 18th, 2008, 3:52pm
 
On a slightly different topic, Creating a timer might be of interest for you, too. Can be used with tanepierre's formatted message.
Page Index Toggle Pages: 1