Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

Date constructor for long.

Thread view: 
Sameer - 12 Sep 2006 08:33 GMT
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);


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.