This worked for me..
long finTime=0;
long startTime=0;
while(true)
{
endTime = System.currentTimeMillis();
while (finTime < 1)
{
endTime = System.currentTimeMillis();
finTime = (endTime - startTime) / 1000;
}
}
sorry ... pressed the post button twise.
Message was edited by:
sridanu
import java.util.*; //for manipulating the time
import java.text.*;
import org.apache.commons.lang.time.*; // formatting numbers
public static String returnDateAndTime(long currentTime)
{
return DateFormatUtils.format(currentTime, "dd-MMM-yyyy HH:mm:ss");
}
use it as System.out.println(returnDateAndTime(System.currentTimeMillis());
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class Time
{
public Time()
{
}
public static void main(String args[])
{
Time t=new Time();
String time=t.CallTime();
System.out.println("Time: "+time);
}
public String CallTime()
{
Date date=new Date();
SimpleDateFormat sdate=new SimpleDateFormat("hh:mm:ssa");
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
int hour24 = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
String result=hour24 +":"+minute;
return result;
}
}
> SimpleDateFormat for the display format
> JLabel to display the time
> javax.swing.Timer (set for 1 sec) to set the label's
> time
>
> But can you explain it in detail.
The [url=http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/Timer.html]API documentation[/url] explains it (and provides a link to a tutorial as well.)