我在互联网上做了一些研究但仍然困惑.UNIX时间通用时间是否像GMT/UTC一样,或者它是否因地方时间而异地变化?
我知道UNIX时间从1970年1月1日00:00:00 GMT算起.当我在Java中使用getTime()函数时(更具体地说,日期d = new Date(); long currentTime d.getTime())我以毫秒为单位获取UNIX时间.现在如果A人和B人使用相同的功能坐在两个不同的时区,他们会得到相同的结果吗?
我有一个非常大的 JSON 文件,格式如下:
[{"fullname": "name1", "id": "123"}, {"fullname": "name2", "id": "245"}, {"fullname": "name3", "id": "256"}]
Run Code Online (Sandbox Code Playgroud)
它看起来像一个 JSONArray。所有记录都写在同一行中。
你能帮我如何使用 Java 解析这个文件吗?我想读取每个 JSON 对象并显示所有全名和 ID。以下是我的尝试,但我的代码不起作用:
import org.apache.commons.lang3.StringEscapeUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
public class JSONFileReaderDriver {
public static void main(String[] args) throws FileNotFoundException,
IOException, ParseException
{
String filename="Aarau";
String src="C:\\"+filename+".json";
JSONParser parser = new JSONParser();
JSONObject obj;
try
{
BufferedReader br=new BufferedReader (new FileReader(src));
obj = (JSONObject) new JSONParser().parse(row);
String fullname=obj.get("fullname");
String id=obj.get("id");
System.out.println ("fullname: "+fullname+" id: "+id);
}catch(Exception …Run Code Online (Sandbox Code Playgroud) 嗨,我有一个文件,其中包含多行日期.我正在提取该日期字段,然后尝试在Date对象中解析它们.我正在使用Java.日期采用以下形式:
"2017年11月13日 - 上午7:03"和我的代码片段如下:
String rpattern = "d MMM, yyyy - hh:MM aa"; //13 Nov, 2017 - 7:03 AM
SimpleDateFormat rsimpleDateFormat = new SimpleDateFormat(rpattern);
Date rtime = rsimpleDateFormat.parse(report_time.trim());
Run Code Online (Sandbox Code Playgroud)
除了2017年10月31日 - 下午5:31之外,该计划适用于几个日期.它标记了此特定日期(2017年10月31日 - 下午5:31)的例外情况,如下所示:
java.text.ParseException:无法解析的日期:"2017年10月31日 - 下午5:31"
,
位于Analysis.SnarlVicRoadIncidentReporting.main的java.text.DateFormat.parse(未知来源)(SnarlVicRoadIncidentReporting.java:54)
任何人都可以帮助我解决这个问题吗?