V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
twirain
V2EX  ›  问与答

字符串时间转 ZonedDateTime 出现的问题

  •  
  •   twirain · 2018-11-12 22:42:34 +08:00 · 1742 次点击
    这是一个创建于 1985 天前的主题,其中的信息可能已经有所发展或是发生改变。
    String time = "11 12 21:29:01 +0800 2018";
    ZonedDateTime c = ZonedDateTime.parse(time, DateTimeFormatter.ofPattern("MM dd HH:mm:ss xx yyyy"));
    System.out.println(c);
    		
    String time2 = "Nov 12 21:29:01 +0800 2018";
    ZonedDateTime b = ZonedDateTime.parse(time2, DateTimeFormatter.ofPattern("MMM dd HH:mm:ss xx yyyy"));
    System.out.println(b);
    

    第一个输出为:2018-11-12T21:29:01+08:00

    第二个直接抛了异常:Exception in thread "main" java.time.format.DateTimeParseException: Text 'Nov 12 21:29:01 +0800 2018' could not be parsed at index 0

    3 条回复    2018-11-13 18:42:14 +08:00
    wdlth
        1
    wdlth  
       2018-11-12 22:53:00 +08:00
    https://repl.it/repls/GlamorousSpecializedGnuassembler

    没有发现异常,你是不是输入了全角空格之类的?
    OscarUsingChen
        2
    OscarUsingChen  
       2018-11-12 23:44:11 +08:00
    Locale 的问题?
    twirain
        3
    twirain  
    OP
       2018-11-13 18:42:14 +08:00 via Android
    用 eclipse 编的,提示 unknown source,参数也都勾上了,不知道什么问题
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1061 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 23:09 · PVG 07:09 · LAX 16:09 · JFK 19:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.