Posted By:
Sumit_Mishra
Posted On:
Tuesday, May 14, 2002 03:51 AM
Hi, Please see the following static method. public static java.sql.Timestamp dateFormatter (String igDate, Locale iLocale) { if (igDate == null) { return null; } java.util.Date lDate = null; java.text.SimpleDateFormat lSimpleDateFormat = (java.text.SimpleDateFormat) java.text.DateFormat.getDateInstance (java.text.DateFormat.SHORT, iLocale); try { lDate = (java.util.Date) lSimpleDateFormat.parse(igDate); } catch(java.text.ParseException e){} if(lDate != null){ return new java.sql.Timestamp(lDate.getTime());
More>>
Hi,
Please see the following static method.
public static java.sql.Timestamp dateFormatter
(String igDate, Locale iLocale)
{
if (igDate == null) {
return null;
}
java.util.Date lDate = null;
java.text.SimpleDateFormat lSimpleDateFormat =
(java.text.SimpleDateFormat)
java.text.DateFormat.getDateInstance
(java.text.DateFormat.SHORT, iLocale);
try
{
lDate = (java.util.Date) lSimpleDateFormat.parse(igDate);
}
catch(java.text.ParseException e){}
if(lDate != null){
return new java.sql.Timestamp(lDate.getTime());
}else{
return null;
}
}
If the input is given as
dateFormatter("05/01/22",java.util.Locale.US)
(the date here is 1st May 2022), the output comes as
2022-05-01 00:00:00.0
This is perfectly fine.
But if the input is given as
dateFormatter("05/01/23",java.util.Locale.US)
(the date here is 1st May 2023), the output comes as
1923-05-01 00:00:00.0.
Any year after 2023 gives the same problem.
I am using Windows NT OS and jdk 1.2.2.
My OS date setting is dd/mm/yyyy.
What can be the issue here?
<<Less