在Java中以JSON格式下载消息后,从Facebook数据转换时间戳记 [英] Converting the timestamp from Facebook data after downloading messages in JSON format in Java
问题描述
我找不到这个问题的答案,因此,一旦找到答案,我觉得发布答案可能会帮助其他人.
I was unable to find an answer to this problem, so once I figured it out, I felt posting the answer might help other people down the road.
问题是当您从Facebook下载消息并以JSON格式下载消息时,时间码需要转换为可在Java程序中使用的格式.
The issue is when you have downloaded your messages from Facebook and you download them in JSON format, the timecode needs to be converted to a format that can be used in your Java program.
Facebook的时间码是一个13位数字,看起来像这样:1548410106047
The timecode from Facebook is a 13 digit number that looks something like this: 1548410106047
推荐答案
该问题的解决方案是:
您必须首先将其转换为Long数据类型,然后像这样简单地制作一个时间戳:
You must first convert it to a Long datatype, then simply make a Timestamp out of it like this:
Long fbt = Long.parseLong(facebookTime);
Timestamp ts = new Timestamp(fbt);
一旦添加了时间戳,您就可以使用它进行任何操作,例如:
Once you have it in a timestamp you can do anything with it such as:
SimpleDateFormat sdf = new SimpleDateFormat("EEEE, MMMM dd, YYYY hh:mm a");
System.out.println(sdf.format(ts));
上面的输出看起来像这样:
The output from above looks like this:
2019年1月25日星期五上午01:55
这篇关于在Java中以JSON格式下载消息后,从Facebook数据转换时间戳记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!