dailymotion视频api,created_time返回不正确

时间:2017-02-18 03:51:02

标签: java date dailymotion-api

我提出了api请求:

https://api.dailymotion.com/videos?fields=channel,channel.name,created_time,duration,id,owner,owner.avatar_240_url,owner.avatar_480_url,owner.screenname,owner.username,thumbnail_240_url,thumbnail_480_url,thumbnail_720_url,title,views_total&list=what-to-watch&limit=12&page=1

created_time值似乎错误,类似于1487308049,其转换为Java DateSunday, January 18, 1970 5:08:28 AM UTC。这可能不对,对吗?

created_time值应为Long,远远大于1487308049

1 个答案:

答案 0 :(得分:1)

我假设您使用Java来解析DailyMotion API结果中的created_time。 在Java中,日期是以毫秒为单位测量的,而在其他一些语言中(读取PHP),则以秒为单位。您获得的create_time值以秒为单位。你只需要在最后添加3个零,然后在将其转换为日期之前将其转换为millisceonds

DateTime dateTime = new DateTime(1487308049L);      
System.out.println("DateTime: " + dateTime);

//DateTime: 1970-01-18T10:38:28.049+05:30

DateTime dateTime2 = new DateTime(1487308049000L);      
System.out.println("DateTime: " + dateTime2); 

//DateTime: 2017-02-17T10:37:29.000+05:30

希望这有帮助