Opa! Tem como acrescentar mais um nível de horário no Java? Tipo, uso um getTimeInstance para pegar a hora, mas quero que mostre também os milisegundos. Tem como fazer isso? Valeu!
Cara existe a class GregorianCalendar:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/GregorianCalendar.html
System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
[]s
Para obter o tempo corrente e imprimir corretamente…
try {
java.util.Date atual = new java.util.Date();
java.text.SimpleDateFormat formater = new java.text.SimpleDateFormat("dd/MM/yyyy hh:mm:ss,SSS);
System.out.println ( formater.format ( atual ) ) ;
} catch (Exception e) {
e.printStackTrace();
}
Boa sorte.
System.currentTimeMilis() te retorna a data em milesegundos.
/**
* Returns the current time in milliseconds. Note that
* while the unit of time of the return value is a millisecond,
* the granularity of the value depends on the underlying
* operating system and may be larger. For example, many
* operating systems measure time in units of tens of
* milliseconds.
*
* <p> See the description of the class <code>Date</code> for
* a discussion of slight discrepancies that may arise between
* "computer time" and coordinated universal time (UTC).
*
* @return the difference, measured in milliseconds, between
* the current time and midnight, January 1, 1970 UTC.
* @see java.util.Date
*/
public static native long currentTimeMillis();