Tuesday, November 14, 2017

Show watch in Console Java

package mine;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

class MyWatch implements Runnable {
DateFormat formate;
Calendar cal;
String time;

public void show() {

System.out.print("\r" + time);
}

@Override
public void run() {
try {
while (true) {

new GregorianCalendar();
cal = Calendar.getInstance();

formate = new SimpleDateFormat("hh:mm:ss");
Date date = cal.getTime();
time = formate.format(date);
show();
Thread.sleep(1000);
}
} catch (Exception e) {
e.getMessage();
}

}

}

public class ShowWatch {

public static void main(String[] args) {
Thread t1 = new Thread(new MyWatch());

t1.start();

}
}

No comments:

Post a Comment