英文:
DateTime with "UTC" Timezone to DateTime only (without the UTC Timezone) conversion in Java
问题
以下是代码的翻译部分:
String s = "2023-02-13 06:10:45.483000 UTC";
TemporalAccessor ta = DateTimeFormatter.ISO_INSTANT.parse(s);
Instant i = Instant.from(ta);
Date d = Date.from(i);
System.out.println(d);
这是我的示例代码,它返回了一个Java错误:
Exception in thread "main" java.time.format.DateTimeParseException: Text '2023-02-13 06:10:45.483000 UTC' could not be parsed at index 10
at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2052)
at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1880)
at App.main(App.java:29)
希望这对你有所帮助。
英文:
I have this sample String "2023-02-13 06:10:45.483000 UTC" and I want to convert this into a simple DateTime format without the Timezone in Java. How do I do this in Java language?
String s = "2023-02-13 06:10:45.483000 UTC";
TemporalAccessor ta = DateTimeFormatter.ISO_INSTANT.parse(s);
Instant i = Instant.from(ta);
Date d = Date.from(i);
System.out.println(d);
This is my sample code and it returns an error from Java:
Exception in thread "main" java.time.format.DateTimeParseException: Text '2023-02-13 06:10:45.483000 UTC' could not be parsed at index 10
at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2052)
at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1880)
at App.main(App.java:29)
答案1
得分: 2
我能够使用以下代码解决我的问题:
private static final DateTimeFormatter BIG_QUERY_PARSER = new DateTimeFormatterBuilder()
.append(DateTimeFormatter.ISO_LOCAL_DATE)
.appendLiteral(' ')
.append(DateTimeFormatter.ISO_LOCAL_TIME)
.appendPattern(" zzz")
.toFormatter(Locale.ENGLISH);
感谢您的评论和解决方案。
英文:
I was able to solve my issue using
private static final DateTimeFormatter BIG_QUERY_PARSER = new DateTimeFormatterBuilder()
.append(DateTimeFormatter.ISO_LOCAL_DATE)
.appendLiteral(' ')
.append(DateTimeFormatter.ISO_LOCAL_TIME)
.appendPattern(" zzz")
.toFormatter(Locale.ENGLISH);
Thank you for the comments/solutions.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论