java.lang.IllegalArgumentException:模式字母太多:m

时间:2016-09-29 12:36:21

标签: java string postgresql datetime

我尝试将此字符串转换为java LocalDateTime

String str = "2016-09-29 09:54:27.850373"

                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.mmmmmm");
                configActivityLog.activityTimeStamp = LocalDateTime.parse(str, formatter);

但是我收到了这个错误:

java.lang.IllegalArgumentException: Too many pattern letters: m

1 个答案:

答案 0 :(得分:2)

s代表秒,而S代表几分之一秒,请参阅Patterns for Formatting and Parsing

查看sample working demo

import java.util.*;
import java.lang.*;
import java.io.*;
import java.time.*;
import java.time.format.*;
class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        String str = "2016-09-29 09:54:27.850373";
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS");
        System.out.println(LocalDateTime.parse(str, formatter));
    }
}