Converting a date string to a DateTime object using Joda Time library

0 votes

We have a date as a string in the following format "02/02/2011 20:27:05". We are using Joda-Time library and would like to convert it to DateTime object. I did:

DateTime dt = new DateTime("04/02/2011 20:27:05")

But I'm getting the following error :

Invalid format: "02/02/2011 14:42:17" is malformed at "/02/2011 14:42:17"

How to convert the above date to a DateTime object?

Jul 23, 2018 in Java by samarth295
• 2,190 points
356 views

1 answer to this question.

0 votes

Use DateTimeFormat:

DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss");
DateTime dt = formatter.parseDateTime(string);
answered Jul 23, 2018 by scarlett
• 1,280 points

Related Questions In Java

0 votes
1 answer

How to convert a date string to a DateTime object using Joda Time library?

DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss"); DateTime dt = ...READ MORE

answered Jan 9 in Java by Daisy
• 8,040 points
26 views
0 votes
1 answer

How to convert a JSON String into Object in Java?

We can easily convert a JSON String ...READ MORE

answered Jun 8, 2018 in Java by parth295
• 4,600 points
219 views
0 votes
1 answer

How to convert a string representation of a hex dump to a byte array using Java?

public static byte[] hexStringToByteArray(String s) { ...READ MORE

answered Sep 26, 2018 in Java by sharth
• 3,320 points
122 views
0 votes
1 answer

Converting ISO 8601-compliant String to java.util.Date

Unfortunately, the time zone formats available to SimpleDateFormat (Java ...READ MORE

answered Nov 27, 2018 in Java by Daisy
• 8,040 points
497 views
0 votes
3 answers

Convert date object to a String

We parse the full date to time ...READ MORE

answered Jul 30, 2018 in Java by samarth295
• 2,190 points
47 views
0 votes
1 answer

How can I convert a String variable to a primitive int in Java

You can convert a String to int by using a function: int ...READ MORE

answered Apr 12, 2018 in Java by sharth
• 3,320 points
85 views
0 votes
2 answers

Integer to String conversion in java

We can do this in 2 ways: String ...READ MORE

answered Jul 27, 2018 in Java by samarth295
• 2,190 points
58 views
0 votes
3 answers

String to Double conversion in java

Double temp = Double.valueOf(str); number = temp.doubleValue(); READ MORE

answered Sep 10, 2018 in Java by Sushmita
• 6,840 points
40 views
0 votes
2 answers

How to left pad a string with zero in java?

String paddedString = org.apache.commons.lang.StringUtils.leftPad("129018", 10, "0") the second ...READ MORE

answered Aug 31, 2018 in Java by Sushmita
• 6,840 points
226 views
0 votes
1 answer

What is the easiest way to iterate through the characters of a string in Java?

The below code seems the easiest to ...READ MORE

answered Jul 13, 2018 in Java by scarlett
• 1,280 points
40 views