Article View: borland.public.jbuilder.java.language
Article #15676how to convert 2digitdate->4digit?
From: Nick Jones
Date: Mon, 10 May 1999 00:00
Date: Mon, 10 May 1999 00:00
35 lines
1295 bytes
1295 bytes
I want to convert a String to a date. The String might contain a two
digit year code so I want the parser of the date to automatically
convert the two digit format to a 4 digit format. This is what I have
so far :
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
try
{
sdf.set2DigitYearStart(sdf.parse("01/01/1950"));
Date date = sdf.parse(tf.getText());
if(date != null)
{
System.out.println(date.toString());
System.out.println(sdf.format(date));
}
else
{
}
}
catch (ParseException parseException)
{
}
I have tried this with and without the call to set2DigitYearStart()
When I type a 2 digit year, the string gets converted to something like
:
10/05/99 -> 10/05/0099
I am not sure what is going on.
Nick
Technical Details
Message-ID:
<37366710.494CDF04@alchemy.co.nz>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,7ef68cf2148b90cb,start X-Google-Attributes: gidf74b3,public From: Nick Jones <n.jones@alchemy.co.nz> Subject: how to convert 2digitdate->4digit? Date: 1999/05/10 Message-ID: <37366710.494CDF04@alchemy.co.nz> X-Deja-AN: 476059893 Content-Transfer-Encoding: 7bit Organization: Alchemy Group Limited X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language