偏移日期时间解析

2024-03-08

需要从格式解析日期时间2016-06-24T13:39:44.687680.

第一步使用,尝试用线路解析没有微秒的时间。

System.out.println(OffsetDateTime.parse("2011-12-03T10:15:30", DateTimeFormatter.ISO_LOCAL_DATE_TIME));

有例外

Exception in thread "main" java.time.format.DateTimeParseException: Text '2011-12-03T10:15:30' could not be parsed: Unable to obtain OffsetDateTime from TemporalAccessor: {},ISO resolved to 2011-12-03T10:15:30 of type java.time.format.Parsed
    at java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:1920)
    at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1855)
    at java.time.OffsetDateTime.parse(OffsetDateTime.java:402)
    at timeread.TimeReading.main(TimeReading.java:18)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.time.DateTimeException: Unable to obtain OffsetDateTime from TemporalAccessor: {},ISO resolved to 2011-12-03T10:15:30 of type java.time.format.Parsed
    at java.time.OffsetDateTime.from(OffsetDateTime.java:370)
    at java.time.format.Parsed.query(Parsed.java:226)
    at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
    ... 7 more
Caused by: java.time.DateTimeException: Unable to obtain ZoneOffset from TemporalAccessor: {},ISO resolved to 2011-12-03T10:15:30 of type java.time.format.Parsed
    at java.time.ZoneOffset.from(ZoneOffset.java:348)
    at java.time.OffsetDateTime.from(OffsetDateTime.java:359)
    ... 9 more

尝试使用DateTimeFormatter with TimeZone

System.out.println(OffsetDateTime.parse("2011-12-03T10:15:30", DateTimeFormatter.ISO_LOCAL_DATE_TIME.withZone(ZoneId.systemDefault())));

类似的例外

Exception in thread "main" java.time.format.DateTimeParseException: Text '2011-12-03T10:15:30' could not be parsed: Unable to obtain OffsetDateTime from TemporalAccessor: {InstantSeconds=1322892930},ISO,Europe/Moscow resolved to 2011-12-03T10:15:30 of type java.time.format.Parsed
    at java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:1920)
    at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1855)
    at java.time.OffsetDateTime.parse(OffsetDateTime.java:402)
    at timeread.TimeReading.main(TimeReading.java:18)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.time.DateTimeException: Unable to obtain OffsetDateTime from TemporalAccessor: {InstantSeconds=1322892930},ISO,Europe/Moscow resolved to 2011-12-03T10:15:30 of type java.time.format.Parsed
    at java.time.OffsetDateTime.from(OffsetDateTime.java:370)
    at java.time.format.Parsed.query(Parsed.java:226)
    at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
    ... 7 more
Caused by: java.time.DateTimeException: Unable to obtain ZoneOffset from TemporalAccessor: {InstantSeconds=1322892930},ISO,Europe/Moscow resolved to 2011-12-03T10:15:30 of type java.time.format.Parsed
    at java.time.ZoneOffset.from(ZoneOffset.java:348)
    at java.time.OffsetDateTime.from(OffsetDateTime.java:359)
    ... 9 more

OffsetDateTime是日期时间的表示 抵消。 创建一个OffsetDateTime,您需要一个区域偏移。

ISO-8601 日历中与 UTC/格林威治有偏移的日期时间 系统,例如 2007-12-03T10:15:30+01:00。

see: https://docs.oracle.com/javase/8/docs/api/java/time/OffsetDateTime.html https://docs.oracle.com/javase/8/docs/api/java/time/OffsetDateTime.html

例如:

OffsetDateTime.parse("2011-12-03T10:15:30+01:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME);

如果您尝试解析日期时间ZoneId,你应该使用ZonedDateTime.

ISO-8601 日历系统中带有时区的日期时间,例如 2007-12-03T10:15:30+01:00 欧洲/巴黎。

see: https://docs.oracle.com/javase/8/docs/api/java/time/ZonedDateTime.html https://docs.oracle.com/javase/8/docs/api/java/time/ZonedDateTime.html

例如:

ZonedDateTime.parse("2011-12-03T10:15:30", DateTimeFormatter.ISO_LOCAL_DATE_TIME.withZone(ZoneId.systemDefault()));

如果您需要的是 ISO-8601 日历系统中没有时区的日期时间,您可以使用LocalDateTime.

ISO-8601 日历系统中没有时区的日期时间,例如 如 2007-12-03T10:15:30。

see: https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html

例如:

LocalDateTime.parse("2016-06-24T13:39:44.687680", DateTimeFormatter.ISO_LOCAL_DATE_TIME);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

偏移日期时间解析 的相关文章

  • 如何使用postman调用REST API进行azure文件存储?

    我想通过postman调用azure的文件存储相关的REST API 以下是我提出请求的方式 我正在请求列出文件存储帐户中的所有共享 如下所述 https learn microsoft com en us rest api storage
  • 如何从 AccountManager.getAccounts() 获取与特定帐户关联的图标

    每个帐户的帐户设置中都会显示一个图标 对于 Google 帐户有一个图标 对于 Facebook 帐户有另一个图标 有没有办法从应用程序的代码中获取该图标 最后我解决了 private Drawable getIconForAccount
  • 在 Windows 7 中,不从命令行强制终止 JVM

    我在 JVM 中运行了 Cobertura 仪器化 jar 当我在运行应用程序的 Windows 控制台中按 Ctrl C 时 JVM 结束并Cobertura 结果已成功刷新到 cobertura ser 文件 但我需要使用命令 工具 不
  • Maven 配置文件相当于 Gradle

    我试图在我的 spring boot 项目构建中实现一个简单的场景 包括 排除依赖项以及根据环境打包 war 或 jar 例如 对于环境dev包括开发工具和包 jar 用于prod包战等 我知道它不再是基于 XML 的配置 我基本上可以在
  • 将json URL导入到java并使用jackson库解析它

    我正在尝试读取 java 中的 json 链接并解析它 以便我可以将它用于其他事务 但问题是我收到错误 我真的不知道该如何处理它们 这是代码 package weather data import weather data import c
  • 全屏独占模式下的 AWT 框架在窗口弹出对话框中最小化

    我正在开发一个在全屏独占模式下使用 awt 框架的应用程序 一切正常 直到弹出窗口可见 这会抢走焦点 我的应用程序将被最小化 这是我的框架的初始化代码 if ApplicationConfig getInstance useFullscre
  • Selenium Webdriver 中显式等待 findElements

    登录后 页面重定向到一个页面 我想等待页面加载 我在其中按 tagName 查找元素 By inputArea By tagName input List
  • 找不到模块:javafx.controls

    我已经下载了JavaFX SDK 解压它并设置PATH TO FX系统变量 如下本说明 https openjfx io openjfx docs install javafx 我使用了以下代码示例 import javafx applic
  • Maven:缺少工件 org.springframework:spring:jar:4.2.6

    我在 SpringToolSuite 中有一个动态 Web 项目 它被转换为 Maven 项目 我遇到问题 缺少工件 org springframework spring jar 4 2 6 我已经尝试清理 重建和运行该项目 它给 读取文件
  • 为什么我无法解开根节点并反序列化对象数组?

    为什么我无法通过展开根节点来反序列化对象数组 import java io IOException import java util Arrays import java util List import org codehaus jack
  • 用 Java 捕获扬声器输出

    使用Java可以捕获扬声器输出吗 此输出不是由我的程序生成的 而是由其他正在运行的应用程序生成的 这可以用 Java 完成还是我需要求助于 C C 我有一个基于 Java 的应用程序 使用过的爪哇声音 https stackoverflow
  • Hibernate3:自引用对象

    需要一些帮助来了解如何执行此操作 我将在文件系统上运行递归 查找 并且希望将信息保留在单个数据库表中 具有自引用的层次结构 这是我想要填充的数据库表结构 目录对象表 id int NOT NULL name varchar 255 NOT
  • 如何在其他窗口之上生成独立的 JFileChooser 对话框?

    Like 其他一些人 https stackoverflow com questions 4161207 javavm windows 7 64bit jfilechooser not showing dialog box谁问过类似的问题
  • 如何根据服务器/环境动态加载服务器配置?

    目前 我设置了 Maven 配置文件 以便能够为不同的环境 开发 演示 暂存 生产等 部署我的项目 并且它工作得很好 但问题是 对于我拥有的每个模块 Web 应用程序 我需要复制 粘贴此配置文件 它们都是属性文件 当我需要更改环境 服务器配
  • 使用 colt java lib 时出现“矩阵太大”异常

    我正在使用 cern colt matrix lib 进行稀疏矩阵计算 但似乎我一直遇到此错误 线程 main 中的异常 java lang IllegalArgumentException 矩阵太大 我认为这是因为构造函数在 nrows
  • Java可以进行进程监控吗?

    是否可以用Java编写一个在托盘中运行的应用程序 并且当启动某个应用程序时 它可以检测到它 我想对某些程序执行此操作 以了解我每周使用它们多长时间 我是 Java 新手 所以我不知道 Java 是否是最适合此操作的语言 或者它是否具有对操作
  • 在 Java Web 应用程序中获取 DataSource 资源

    我的 context xml 文件中有以下资源标记
  • LinkedBlockingQueue 抛出 InterruptedException

    我有这段代码 ALinkedBlockingQueue应该只抛出一个Exception如果在等待添加到队列时被中断 但这个队列是无限的 所以它应该尽快添加 为什么我的关闭方法会抛出一个InterruptedException private
  • 确保对象实现 Comparable

    我有一个小问题 想知道如何解决它 我有一个通用类Tuple
  • 使用反射 API 填充 Proto 中的地图字段

    我正在尝试编写一个模块 该模块将获取 Message Builder 和从字段名称到值的映射 并将用值填充构建器 一切正常 直到我遇到地图字段 使用 Proto3 我收到一条特定消息 我知道我可以执行该消息的字段 builder b put

随机推荐

  • Symfony2 FOSUserBundle 错误 - FileLoaderImportCircularReferenceException

    我正在尝试在新的 symfony2 项目上安装 FOSUserBundle 我已按照以下步骤安装它 但仍然遇到此错误 FileLoaderImportCircularReferenceException in FileLoader php
  • OrientDB性能

    我一直在阅读有关 OrientDB 性能基准的帖子 http technet weblineindia com web introduction to orientdb a nosql dbms http technet weblinein
  • 蚀。将类型层次结构复制到剪贴板

    When I open Type Hierarchy in Eclipse either F4 or Ctrl T is there any way to copy the result tree as text into the clip
  • Rails:simple_form:从复选框集合中获取空字符串

    我的观点中有以下代码 每当我提交表单时 我都会得到类似的值 admin moderator 但我期待类似的事情 admin moderator 为什么是这样 此外 我做了一个检查元素 并且有一个
  • 为什么没有纯 Python SSH1(版本 1)客户端实现?

    似乎有一些很好的纯 Python SSH2 客户端实现 但我还没有找到一个适用于 SSH1 的客户端 除了对这样的项目缺乏兴趣之外 还有什么具体原因吗 我完全意识到许多 SSH1 漏洞 但是对于我们这些想要编写 SSH 客户端来管理仅支持
  • 反应本机滚动视图不会从文本输入内部滚动

    我在滚动视图中添加了多文本输入 问题是当我想从文本输入内部向下滚动时 我将手指放在文本输入内部并向下滚动 但它没有向下滚动页面 有没有办法解决这个问题 这是示例代码 export default class ScrollViewWithTe
  • 根据尺寸类别更改约束乘数

    是否可以根据当前的尺寸类别为约束赋予不同的乘数 我的观点是 对于常规尺寸类宽度 我希望其尺寸为屏幕尺寸的一半 对于紧凑尺寸类宽度 我希望其尺寸为屏幕尺寸的 80 在故事板中 我可以选择将不同大小类别的不同变量添加到约束常量值中 但不能添加它
  • 如何更新vcpkg本身?

    我已经安装了 vcpkg 一个 C 包管理器 现在过了一段时间 我想更新一下 我怎样才能做到这一点 我需要卸载并重新安装吗 更新 vcpkg git 克隆的最佳方法是 将所有已安装端口的列表保存在某处 git pull 删除
  • geom_histogram:错误的垃圾箱?

    我正在使用 ggplot 2 1 0 来绘制直方图 并且我对直方图箱有意外的行为 我在这里举了一个左封闭 bin 的示例 即 0 0 1 binwidth 为 0 1 mydf lt data frame myvar c 1 0 5 0 4
  • 有没有更好的方法来打印cout最多N个字符的字符串?

    编辑 我发送的是二进制文件而不是字符串 我的测试是使用 html 页面 所以在这个例子中我只使用一个字符串 但我的问题是关于二进制 向量和使用 ostream 进行调试 我这样做可以消除一些混乱 我有以下代码 cout lt lt stri
  • 以 Django 形式访问 POST 数据

    我一直在使用这个网站 http jacobian org writing dynamic form generation 作为如何在 Django 中制作动态表单的示例 在他看来 他使用 if request method POST for
  • 在unity3D android中本地保存大量数据的最佳方法? [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我正在开发一个2D游戏 稍后将用作摊位的广告活动 我需要存储用户信息 姓名 号码 电子邮件和分数 这些
  • java servlet:请求参数包含加号

    请求参数就像decrypt param 5FHjiSJ6NOTmi7 2tnnkQ 在 servlet 中 当我尝试通过以下方式打印参数时String param request getParameter param I get 5FHji
  • javascript 点击事件处理程序在没有点击的情况下触发

    为什么在没有单击指定按钮的情况下会触发此函数 我查看了一些类似的问题 但没有一个涉及此代码结构 可能是我丢失的明显原因 document getElementById main btn addEventListener click hide
  • 如何在 CSS 中设置背景图像不透明度而不使用伪之前/之后和/或定位的 div

    我有一个由 CMS 生成的 div 其中包含一个背景图像 我想更改该背景图像的不透明度 而不影响该 div 子元素的不透明度 https jsfiddle net L5b81yqo https jsfiddle net L5b81yqo H
  • PyCharm 和 VirtualEnvs - 如何删除旧版本

    如何从 PyCharm 中删除遗留项目的所有痕迹 背景 我今天从 PyCharm 社区版升级到 PyCharm 专业版 原因是这样我就可以从事 Django 项目 特别是一个名为 deals 的新兴遗留项目 我删除了旧项目文件夹 然后 我打
  • Ember JS/Handlebars 视图助手

    目前 如果我们将视图定义为 view App myView ember handlebars 会将视图元素包裹在一个 div class ember view 有办法阻止这种情况吗 您可能想将 tagName 设置为 App MyView
  • “无法从安装目录获取安装脚本的一致路径”

    我正在使用 pip 从 git 存储库安装包 pip install e git git github com knipknap SpiffWorkflow git master egg SpiffWorkflow dev 克隆存储库没有问
  • 如何编写一个 C++ 程序来过滤掉非整数?

    像这样的东西 cout lt lt Enter the number of columns cin gt gt input while input int cout lt lt endl lt lt Column size must be
  • 偏移日期时间解析

    需要从格式解析日期时间2016 06 24T13 39 44 687680 第一步使用 尝试用线路解析没有微秒的时间 System out println OffsetDateTime parse 2011 12 03T10 15 30 D