Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.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 Android-根据GMT设置时间数据_Java_Android_Android Studio - Fatal编程技术网

Java Android-根据GMT设置时间数据

Java Android-根据GMT设置时间数据,java,android,android-studio,Java,Android,Android Studio,如何根据用户的时间组织保存在字符串中的时间数据 比如,; 默认数据(小时/分钟/秒)=03:48:21 此数据为GMT+2的用户的数据 它应该是02:48.21。tl;博士 OffsetTime .的( parse(“03:48:21”), 小时分区偏移量(2) ) .withOffsetSameInstant​( ZoneOffset.UTC ) .toString() 01:48:21Z 使用日期时间类型 如何组织保存在字符串中的时间数据 不要使用字符串存储其他类型。如果有日期时间值,请

如何根据用户的时间组织保存在字符串中的时间数据

比如,; 默认数据(小时/分钟/秒)=03:48:21

此数据为GMT+2的用户的数据

它应该是02:48.21。

tl;博士
OffsetTime
.的(
parse(“03:48:21”),
小时分区偏移量(2)
)
.withOffsetSameInstant​( 
ZoneOffset.UTC
)
.toString()
01:48:21Z

使用日期时间类型 如何组织保存在字符串中的时间数据

不要使用
字符串
存储其他类型。如果有日期时间值,请使用日期时间类型。Java在JSR 310中定义的Java.time类中提供了业界领先的日期时间类型

LocalTime
如果
03:48:21
是一天中的某个时间,请使用

一天中没有日期的时间在区域或偏移中没有意义 …根据用户的时间…GMT+2…03:48:21…的用户数据应显示为02:48.21

在我看来,从逻辑上讲,一天中没有日期的时间不能放在一个或多个事件的上下文中

OffsetTime
time类提供了这个类。我假设这个类的存在仅仅是为了支持标准SQL,其中提到了一天中的某个时间和偏移量。然而,在我看来,这个概念毫无意义。但如果你坚持使用它,那就随它去吧

指定与您的
LocalTime
耦合的

LocalTime lt=LocalTime.parse(“03:48:21”);
区域偏移量=小时的区域偏移量(2);
OffsetTime ot=OffsetTime.of(lt,offset);
OffsetTime otUtc=ot.withOffsetSameInstant​(ZoneOffset.UTC);
System.out.println(“ot.toString():”+ot);
System.out.println(“otUtc.toString():”+otUtc);
请参阅此代码

ot.toString():03:48:21+02:00

otUtc.toString():01:48:21Z

该输出末尾的
Z
表示UTC,与UTC的偏移量为零小时分秒,
+00:00
。根据航空/军事传统,
Z
发音为“Zulu”

LocalTime localTime = LocalTime.parse( "03:48:21" ) ;