Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7081737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:57:30+00:00 2026-05-28T06:57:30+00:00

I am working in a project that reads files and processes data. There I

  • 0

I am working in a project that reads files and processes data. There I got to work with dates for example:

  1. 2012-01-10 23:13:26
  2. January 13, 2012

I found the package Joda, kinda interesting package but don’t know if it is the easiest around.

I was able to parse the first example to a DateTime object (Joda) reg-ex and String manipulation. (Ex: by replacing the space by ‘-‘ and passing it to constructor.

new DateTime("2012-01-10 23:13:26".replace(' ', '-'))

I guess it worked, but the problem is with the second format. How can I use such an input to extract a an object, preferably a Joda object. I sure can write a function to change the format to what Joda supports, but was wondering if there would be some other way (even some native Java library) to do it.

If there are any thing better than Joda out there, please let me know it as well.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:57:31+00:00Added an answer on May 28, 2026 at 6:57 am

    Using Joda-Time, take a look at DateTimeFormat; it allows parsing both kind of date strings that you mention (and almost any other arbitrary formats). If your needs are even more complex, try DateTimeFormatterBuilder.

    To parse #1:

    DateTimeFormatter f = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    DateTime dateTime = f.parseDateTime("2012-01-10 23:13:26");
    

    Edit: actually LocalDateTime is a more appropriate type for a datetime without a time zone:

    LocalDateTime dateTime = f.parseLocalDateTime("2012-01-10 23:13:26");
    

    And for #2:

    DateTimeFormatter f = DateTimeFormat.forPattern("MMMM dd, yyyy");
    LocalDate localDate = f.parseLocalDate("January 13, 2012");
    

    And yes, Joda-Time is definitely the way to go, as far as Java date & time handling is concerned. 🙂

    As mostly everyone will agree, Joda is an exceptionally user-friendly library. For example, I had never done this kind of parsing with Joda before, but it took me just a few minutes to figure it out from the API and write it.

    Update (2015)

    If you’re on Java 8, in most cases you should simply use java.time instead of Joda-Time. It contains pretty much all the good stuff—or their equivalents—from Joda. For those already familiar with Joda APIs, Stephen Colebourne’s Joda-Time to java.time migration guide comes in handy.

    Here are java.time versions of above examples.

    To parse #1:

    DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    LocalDateTime dateTime = LocalDateTime.from(f.parse("2012-01-10 23:13:26"));
    

    You cannot parse this into ZonedDateTime or OffsetDateTime (which are counterparts of Joda’s DateTime, used in my original answer), but that kinda makes sense because there’s no time zone information in the parsed string.

    To parse #2:

    DateTimeFormatter f = DateTimeFormatter.ofPattern("MMMM dd, yyyy");
    LocalDate localDate = LocalDate.from(f.parse("January 13, 2012"));
    

    Here LocalDate is the most appropriate type to parse into (just like with Joda-Time).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're currently working on a python project that basically reads and writes M2M data
I´m working on a project that basically will show some data collected from hardware
My company is working on a project that needs to read XML files within
I'm working on a script that generates Visual Studio 2005 C++ project files (.vcproj).
i am working on a project that need to upload files from iphone to
I have a project I'm working on that requires our WPF application read SMS
I am working a project that does not have a trunk / branches /
I'm working on project that lets users choose some scientific authors and columnists and
Working on a project that parses a log of events, and then updates a
I am working on a project that requires the manipulation of enormous matrices, specifically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.