Java Date parse String like "2020-04-03 09:10:40.325"

Description

Java Date parse String like "2020-04-03 09:10:40.325"

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
  public static void main(String[] args) {
    String input = "2020-04-03 09:10:40.325";

    // Prepare the pattern
    String pattern = "yyyy-MM-dd HH:mm:ss.SSS";

    SimpleDateFormat sdf = new SimpleDateFormat(pattern);

    // Parse the text into a Date object
    Date dt = sdf.parse(input, new ParsePosition(0));
    System.out.println(dt);//from   w w w.  ja va  2  s  . co m

  }
}



PreviousNext

Related