How can I convert a String formatted in this way into a Date using Java?

AndreaNobili :

Into a Java application I have this String representing a timestamp containing values like this: 2009-10-17 05:45:14.000

As you can see the string represents the year, the month, the day, the hour, the minute, the second and the millisencond.

I have to convert a String like this into a Date object (if possible bringing also the millisecond information, is it possible?)

How can I correctly implement it?

M.Ismail :

You can use SimpleDateFormat to parse a given string date according to a given pattern, it also supports milliseconds, like this:

SimpleDateFormat format= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
Date date=format.parse("2009-10-17 05:45:14.050");

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

In python pandas, how can I convert this formatted date string to datetime

How to convert date to formatted string

How can I convert object keys & values to formatted string?

How can I keep a date formatted in R using sqldf?

How to convert a UTC String to a Formatted Date in jQuery

Android, How can I Convert String to Date?

How can I convert date to string in python?

How can I convert string date to NSDate?

How can I convert a string into a date?

How can I convert string date to NSDate?

How can I convert Date JsonObject to String?

How can i generate a formatted random string using ReactJS

Is there any way I can write (copy-paste) nicely-formatted SQL queries in Java string literals using Eclipse?

How can I convert sperated date string to consecutive date string

How can I parse a date (provided as a string) in the "ddMM" format and convert it to a Date Object in Java?

How can I convert a specific string date to date or datetime in Spark?

how do i convert unix time stamp to formatted date while using json_extract_scalar in bigquery

How can i store a formatted string in json

How to convert a date formatted string before 1970 into a timestamp in windows

How to convert a date formatted (YYMMDD) as string but with 00 days?

How can i Convert this simple async,await formatted code using Future and .then() in dart (Flutter)?

How can I convert an empty string value to a nullable date value?

How can I convert date string to data in javascript in different timezone?

How can I convert a custom `dayHour` string variable to date format?

How can i convert String to Date when it has "TRT" in it

In Jenkins pipeline, how can I convert a String to Date?

How can I convert this string to a javascript Date object?

how I can convert an specific character string to date time in r?

How can I convert a specific string format to date or datetime in Spark?