我尝试将此字符串转换为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
答案 0 :(得分:2)
s
代表秒,而S
代表几分之一秒,请参阅Patterns for Formatting and Parsing。
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));
}
}