Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 时间戳的日期格式?_Java - Fatal编程技术网

Java 时间戳的日期格式?

Java 时间戳的日期格式?,java,Java,我有以下日期字符串: 1477547160000+0800 时间戳有日期格式吗 另外,没有日期格式来解析时间戳,如中所述,假设+之前的数字是历元毫秒,而+之后的数字是时区偏移量,您可以尝试以下方法: String input = "1477547160000+0800"; long epoch = Long.parseLong(input.substring(0, input.length() - 5)); int offset = Integer.parseInt(input.substrin

我有以下日期字符串:

1477547160000+0800

时间戳有日期格式吗


另外,没有日期格式来解析时间戳,如

中所述,假设
+
之前的数字是历元毫秒,而
+
之后的数字是时区偏移量,您可以尝试以下方法:

String input = "1477547160000+0800";
long epoch = Long.parseLong(input.substring(0, input.length() - 5));
int offset = Integer.parseInt(input.substring(input.length() - 5));
int offsetHour = offset / 100;
int offsetMin = offset % 100;

OffsetDateTime t = Instant
    .ofEpochMilli(epoch)
    .atOffset(ZoneOffset.ofHoursMinutes(offsetHour, offsetMin));
现在您有了
OffsetDateTime
实例,您可以将其转换为所需格式的
String
。默认值为:

t.toString() => "2016-10-27T13:46+08:00"
如果需要特定格式,可以使用
DateTimeFormatter

t.format(new DateTimeFormatter(your_format_here));

左边的数字是历元的毫秒数(如
System.currentTimeMillis()
)。右边的数字告诉您时区。字符串的格式如何?这些毫秒是1970年以来的吗?如何解释时区?我从响应中得到它,因此,我想知道是否有“yyyy-mm-dd”来解析这个字符串。。好吧,没有,但是有没有一些文档说明如何解释响应?不幸的是没有。。。但需要显示为正确的日期字符串。。