import java.util.*;
import java.text.*;
public class DateDemo1 {
public static void main(String args[]) throws ParseException {
Calendar cal = Calendar.getInstance();
cal.set(2006,7,1);
Date date = cal.getTime();
long longTime = date.getTime();
System.out.println("Long representation of date:"+longTime);
Date temp= new Date(longTime);
Date temp1= new Date(1154417769674);
}
}
Please study the code given above.
If the longTime variable is passed as it is programmatically to Date,
then there is no compilation error.
Date temp= new Date(longTime);
But, if i note it down and pass it like this
Date temp1= new Date(1154417769674);
The error is
DateDemo1.java:13: integer number too large: 1154417769674
Date temp1= new Date(1154417769674);
What may be the problem?
Manish Pandit - 12 Sep 2006 08:41 GMT
You are supposed to put an L at the end to denote a Long.
Date temp1= new Date(1154417769674L);
-cheers,
Manish
Bhanu - 12 Sep 2006 08:44 GMT
> import java.util.*;
> import java.text.*;
[quoted text clipped - 22 lines]
>
> What may be the problem?
The problem is you are using a numeral literal which is by default
treated as integer. U need to append a L after the nubmer(not sure may
be before it). So that it is converted to long.
Bhanu - 12 Sep 2006 08:51 GMT
> import java.util.*;
> import java.text.*;
[quoted text clipped - 22 lines]
>
> What may be the problem?
The problem is you are using a numeral literal which is by default
treated as integer. U need to append a L after the nubmer(not sure may
be before it). So that it is converted to long.
I mean pass it like
new Date(1154417769674L);