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 8357109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:22:49+00:00 2026-06-09T10:22:49+00:00

My date string format is like this: Jan 2, 2012 After the Instant.parse() method,

  • 0

My date string format is like this: Jan 2, 2012
After the Instant.parse() method, instant instance becomes the date of Jan 1, 2012, which is 1 day earlier, why? If the original date string is jan 1, 2012, the Instant will be the date of Dec 31, 2011.

String dateString="Jan 1, 2012";
Instant instant = Instant.parse(dateString, new DateTimeFormatterBuilder()
.appendMonthOfYearShortText()
.appendLiteral(" ")
.appendDayOfMonth(1)
.appendLiteral(", ")
.appendYear(4, 4)
.toFormatter());

DateTime dateTime = new DateTime(instant);
Date date = new Date(dateTime.getMillis());

document.append("time", new Date(dateTime.getMillis()));
tagsDbCollection.insert(document);

I’m using MongoDB to store these dates. I’ve tested and it shows when formatting date string->instant there’s no mistake.
But when I insert this Date type object into MongoDB, the date string in the MongoDB becomes 1 day earlier., why?

In MongoDB:

 /* 0 */
    {
      "_id" : ObjectId("50221a40da74d74053abb445"),
      "time" : ISODate("2011-12-31T14:00:00Z")
    }
  • 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-06-09T10:22:51+00:00Added an answer on June 9, 2026 at 10:22 am
    final String dateString = "Jan 2, 2012";
    final DateTimeFormatter dtf = new DateTimeFormatterBuilder().appendMonthOfYearShortText().appendLiteral(" ").appendDayOfMonth(1).appendLiteral(", ").appendYear(4, 4).toFormatter();
    final DateTime jodaDate = dtf.parseDateTime(dateString);
    System.out.println(jodaDate);
    final Date javaDate = new Date(jodaDate.getMillis());
    System.out.println(javaDate); 
    

    Output is

    2012-01-02T00:00:00.000+02:00
    Mon Jan 02 00:00:00 EET 2012  
    

    Next for:

    final String dateString = "Jan 1, 2012";
    

    output is:

    2012-01-01T00:00:00.000+02:00
    Sun Jan 01 00:00:00 EET 2012
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a date string which looks like this: Thu Feb 09 2012 01:50:00
I'd like to use date time format string (possibly UTC) which is understandable and
I want to show a date string in this format: Jun 27, 2012 .
I would like to parse a date. My String date is Thu Jan 19
I have a date/time string like this: 180510_112440 in this format ddmmyy_hhmmss I need
I take date into string . date format is like this and string is
The format of my date string looks like this: yyyy-MM-ddTHH:mm:ss-0Z00 Example 1 : 2010-03-05T07:03:51-0800
I have a date in String format, mm/dd/yyyy I want to convert this to
i have the date in a string format like so '11/2/2009' (m/d/yyyy) I need
I Looking for a method that convert time string into Calendar look like this:

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.