Pinky
Pinky

Reputation: 701

Unresolved compilation while creating date object with long :Java

I tried the following code.

System.out.println(new Date(1268234290000));

It throws Exception

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
The literal 1268234290000 of type int is out of range 

How to resolve?

Upvotes: 2

Views: 283

Answers (1)

Suresh Atta
Suresh Atta

Reputation: 122018

Since it's a long value append L

 System.out.println(new Date(1268234290000L));

Java Language Specification

An integer literal is of type long if it is suffixed with an ASCII letter L or l (ell); otherwise it is of type int (§4.2.1).

Upvotes: 7

Related Questions