dcsimg
Is it the normal behaviour of SimpleDateFormatter to allow year upto 9 digit if i set the pattern as "MM/dd/yyyy"
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   J_R
Posted On:   Wednesday, July 23, 2003 04:24 AM

Here is the code. SimpleDateFormat tempF = new SimpleDateFormat("MM/dd/yyyy"); tempF.setLenient(false); JFormattedTextField tempt = new javax.swing.JFormattedTextField(tempF); Now if i creat SimpleDateFormat with the string MM/dd/yy the behaviour of JtextField is normal. By normal i mean it accepts date as 11/11/11 only and not 11/11/11111111 But if i create SimpleDateFormate with String MM/dd/yyyy the formattted textfield can accept year upto 9 digit. i mean i can enter date as 02/03/12345678 Howver i was expecting that user can only enter 02/03/1234 [after validation] but he can enter value 02/0   More>>

Here is the code.

			
SimpleDateFormat tempF = new SimpleDateFormat("MM/dd/yyyy");
tempF.setLenient(false);
JFormattedTextField tempt = new javax.swing.JFormattedTextField(tempF);




Now if i creat SimpleDateFormat with the string MM/dd/yy the behaviour of JtextField is normal.

By normal i mean it accepts date as 11/11/11 only and not 11/11/11111111

But if i create SimpleDateFormate with String MM/dd/yyyy

the formattted textfield can accept year upto 9 digit.

i mean i can enter date as

02/03/12345678

Howver i was expecting that user can only enter

02/03/1234 [after validation]

but he can enter value

02/03/12345678

??
any idea??
the validation for MM/dd/yy is working fine.    <<Less

Re: Is it the normal behaviour of SimpleDateFormatter to allow year upto 9 digit if i set the pattern as "MM/dd/yyyy"

Posted By:   J_R  
Posted On:   Wednesday, July 23, 2003 04:57 AM

Here is the test code


import java.text.SimpleDateFormat;
import java.text.ParseException;


public class SimpleDateFormatterTest
{
public static void main(String args[])
{
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
SimpleDateFormat sdf1 = new SimpleDateFormat("dd/MM/yy");

sdf.setLenient(false);
String dateStr = "12/03/123456789";
try
{
System.out.println("Date after format : dd/MM/yyyy"+sdf.format(sdf.parse(dateStr)));//itdont
System.out.println("Date after format dd/MM/yy : "+sdf1.format(sdf1.parse(dateStr)));//it behaves normally
}
catch (ParseException e)
{
e.printStackTrace();
}
}

}




any idea how to go ahead???
About | Sitemap | Contact