Contenido de certificación
Buscar
Social
Ofertas laborales ES
« Date-Time API (JAVA 8) | Main | Pregunta sobre Java »
lunes
abr072014

Más sobre GregorianCalendar....

¿Cuál es la siguiente salida y por qué?

Aclaraciones: se dispone de un equipo bastante potente a la hora de ejecución, y el día de ejecución es: 7 de Abril de 2014

NOTA: no vale hacer uso de IDE.
01.package es.orange.gateway.tools;
02. 
03.import java.text.SimpleDateFormat;
04.import java.util.Calendar;
05.import java.util.GregorianCalendar;
06. 
07.public class Pruebas {
08. 
09.    /**
10.     * @param args
11.     */
12.    public static void main(String[] args) {
13. 
14.        GregorianCalendar gc1 = new GregorianCalendar();
15. 
16.        gc1.set(Calendar.MONTH, 4);
17. 
18.        try {
19.            Thread.sleep(10);
20.        } catch (InterruptedException e) {
21.            // TODO Auto-generated catch block
22.            e.printStackTrace();
23.        }
24.        GregorianCalendar gc2 = new GregorianCalendar();
25. 
26.        gc2.set(Calendar.MONTH, 4);
27. 
28.        System.out.println(gc2.compareTo(gc1));
29.         
30.        GregorianCalendar gc3 = new GregorianCalendar();
31. 
32.        gc3.set(Calendar.MONTH, 4);
33.         
34.        GregorianCalendar gc4 = new GregorianCalendar();
35. 
36.        gc4.set(Calendar.MONTH, 4);
37. 
38.        System.out.println(gc4.compareTo(gc3));
39.         
40.        GregorianCalendar gc5 = new GregorianCalendar();
41. 
42.        gc3.set(Calendar.MONTH, 4);
43.         
44.        GregorianCalendar gc6 = new GregorianCalendar();
45. 
46.        gc6.set(Calendar.MONTH, 16);
47. 
48.        System.out.println(gc5.compareTo(gc6));
49. 
50.        System.out.println(new SimpleDateFormat("dd/MM/yyyy").format(gc6.getTime()));
51. 
52.    }
53. 
54.}

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>