Calendar.getInstance() devuelve un objeto GregorianCalendar cuyos campos and sido inicializados con la fecha y hora actual:
Calendar rightNow = Calendar.getInstance();
int julianDay = rightNow.get(Calendar.DAY_OF_YEAR);
int ccyy = rightNow.get(Calendar.YEAR);
int month = rightNow.get(Calendar.MONTH) + 1;
int day = rightNow.get(Calendar.DATE);
int hour12 = rightNow.get(Calendar.HOUR);
int hour24 = rightNow.get(Calendar.HOUR_OF_DAY);
int minute = rightNow.get(Calendar.MINUTE);
int second = rightNow.get(Calendar.SECOND);
int millisec = rightNow.get(Calendar.MILLISECOND);
// Create a copy of the rightNow Calendar object
Calendar baseCal = (Calendar)rightNow.clone();
// Subtract 5 days from the date
rightNow.add(Calendar.DATE, -5);
// Increments the date by one
rightNow.roll(Calendar.DATE, true);
// Decrements the date by one
rightNow.roll(Calendar.DATE, false);
// Returns true when rightNow is later than baseCal (false in this example)
boolean a = rightNow.after(baseCal);
// Returns true when rightNow is earlier than baseCal (true in this example)
boolean b = rigthNow.before(baseCal);
// Returns true when rightNow is equal to baseCal (false in this example)
boolean e = rightNow.equals(baseCal);
// Set the Calendar to a specific date (ccyy, month, day, hour, minute, second)
rightNow.set(1960, 7, 21, 10, 30, 30);
// Returns a Date object for the Calendar object
Date date = rightNow.getTime();
En el siguiente enlace puedes encontrar más informacions sobre la clase calendar:
No hay comentarios:
Publicar un comentario