🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.lenguajes.java
Article #18065

Re: Convertir String a Date

#18065
From: Carlos P�rez
Date: Thu, 28 Sep 2000 00:00
60 lines
2753 bytes
Hola!

    Te dice que el mes 11 es Diciembre porque:

        month - the value used to set the MONTH time field. Month value is
0-based. e.g., 0 for January.

    lo que significa que el mes 0 es Enero, el 1 Febrero, y el 11 Diciembre

    Esto esta en la documentacion del metodo set de la clase Calendar, de la
que hereda GragorianCalendar.

Saludinos.
--
-----------------------------------------------------
Carlos P�rez Haur�e
http://personal2.iddeo.es/keni


"Ft" <ft@NOSPAMiwmail.com> escribi� en el mensaje
news:TBKA5.4458$LH4.23451@telenews.teleline.es...
> Hola al grupo:
>
> La cosa es que tengo una cadena tal como '23-11-2001' y quiero convertirla
a
> Date, �por qu� no hace bien la transformaci�n... me dice que es Diciembre
> (en este caso concreto) o cualquier otra cosa (con otras fechas).
>
> A ver si alquien puede ayudarme, gracias...
> Por cierto, que la primera l�nea es porque el texto est� en un JTextField
y
> todo esto est� en la clase que toma los eventos del foco... lo que quiero
es
> comprobar que la fecha introducida es correcta, antes de que el JTextField
> pierda el Foco...
>
>   Document doc = ((JTextComponent) e.getComponent()).getDocument();
>     try {
>      int year = Integer.parseInt( doc.getText( 6, 4 ) );
>      int month = Integer.parseInt( doc.getText( 3, 2 ) );
>      int day = Integer.parseInt( doc.getText( 0, 2 ) );
>      GregorianCalendar calendar = new GregorianCalendar();
>      calendar.set( year, month, day );
>      Date ts = calendar.getTime();
>      System.out.print( day );
>      System.out.print( month );
>      System.out.println( year );
>      System.out.println( ts );
>     } catch (BadLocationException ble) {
>      System.out.println( "Error al acceder a la cadena: " +
> ble.offsetRequested() );
>     } catch (NumberFormatException nfe) {
>      System.out.println( nfe );
>     } catch (IllegalArgumentException iae) {
>      System.out.println( "Mierda" );
>     }
>
> Gracias.
>
>
Technical Details
Message-ID: <A5MA5.20744$LH4.52293@telenews.teleline.es>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <TBKA5.4458$LH4.23451@telenews.teleline.es>

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: 1116f3,e48ea1f220c97ab7,start
X-Google-Attributes: gid1116f3,public
From: "Carlos P�rez" <keni@retemail.es>
Subject: Re: Convertir String a Date
Date: 2000/09/28
Message-ID: <A5MA5.20744$LH4.52293@telenews.teleline.es>
X-Deja-AN: 675219318
References: <TBKA5.4458$LH4.23451@telenews.teleline.es>
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
X-Complaints-To: usenet@teleline.es
X-Trace: telenews.teleline.es 970165728 62.83.26.140 (Thu, 28 Sep 2000 20:28:48 MET DST)
Organization: Clientes_Teleline
X-MSMail-Priority: Normal
NNTP-Posting-Date: Thu, 28 Sep 2000 20:28:48 MET DST
Newsgroups: es.comp.lenguajes.java