开发者

converting milliseconds value to date?

开发者 https://www.devze.com 2023-01-24 19:43 出处:网络
consider the followign code: public void convertTime() { DateFormat df = new SimpleDateFormat(dateFormat);

consider the followign code:

public void convertTime()
{
    DateFormat df = new SimpleDateFormat(dateFormat);
    Date date;
    Date date2;

    date = df.parse("15/01/2010 21:58:54");
    date.getTime();                     //produces 1263585534000

    date2 = new Date(date.getTime());  //this is ok, compiles
    date2 = new Date(1263585534000);   //gives an error: The literal 1263585534000 of type int is out of range
}

I wonder how can i convert this long number into date format and why am i ge开发者_如何学Pythontting this error?

Thank you


1263585534000 is bigger than 2^31-1. Use L to indicate a Long.

date2 = new Date(1263585534000L);


date2 = new Date(1263585534000L);

ending with L for long literal to indicate it is a long number.

0

精彩评论

暂无评论...
验证码 换一张
取 消