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

  • Home
  • SEARCH
  • 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 8902883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:43:40+00:00 2026-06-15T01:43:40+00:00

I have a date string of format MM/dd/yyyy that I am parsing using SimpleDateFormat

  • 0

I have a date string of format MM/dd/yyyy that I am parsing using SimpleDateFormat

Now say the startDateString is 11/26/2012 for the code given below. I set the time zone to America/New_York

SimpleDateFormat df=new SimpleDateFormat("MM/dd/yyyy");

Date st = df.parse(startDateString);

Calendar startDate = Calendar.getInstance(TimeZone.getTimeZone("America/New_York"));

System.out.println("BEFORE : Start Date :"+startDate.getTime());

startDate.setTime(st);

System.out.println("AFTER : Start Date :"+startDate.getTime());

DateTimeZone timezone = DateTimeZone.forID("America/New_York");

DateTime actualStartDate = new DateTime(startDate,timezone);

System.out.println("JODA DATE TIME "+ actualStartDate);

The outout of above code snippet:

BEFORE : Start Date :Tue Nov 27 12:26:51 IST 2012

AFTER : Start Date :Mon Nov 26 00:00:00 IST 2012 //ok it sets date to 26th
                                                 //with all time parameters as 0.

JODA DATE TIME 2012-11-25T13:30:00.000-05:00 // here the date and 
                                             // time parameter are changed

What my problem is when I create my actualStartDate like this :

DateTime actualStartDate = new DateTime(startDate,timezone);

The date changes to 25 and the time changes to 13:00:00
I think this is because of timezone zone difference between India and US (total -10:30 from IST Indian time)

What I want is JODA DATE TIME 2012-11-26T00:00:00.000-05:00

Do I manually set the parameters of time inside my startDate calendar instance to 0 ?

  • 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-15T01:43:41+00:00Added an answer on June 15, 2026 at 1:43 am

    I suspect the problem is that you’re parsing in your default time zone. This:

    AFTER : Start Date :Mon Nov 26 00:00:00 IST 2012
    

    shows that the instant in time you’re using is midnight IST – not midnight in New York or in UTC. Currently IST is 18:30 in UTC, so the instant you’re representing is 25-11-25T18:30:00Z.

    When you convert that into New York time, you end up with 2012-11-25T13:30:00-05:00, which is exactly what Joda Time is doing.

    I would strongly advise that:

    • You avoid using the Java libraries at all (that’s where all the problems have come from here – both in parsing, and the result of Date.toString() confusing you)
    • You use LocalDate to represent a date, rather than DateTime. You’re trying to represent a date after all, not an instant in time. This bypasses time zones entirely, as a date doesn’t have a time zone.

    Sample code:

    import java.util.*;
    
    import org.joda.time.*;
    import org.joda.time.format.*;
    
    public class Test {
        public static void main (String[] args) {
            String text = "11/26/2012";
            DateTimeFormatter formatter =
                DateTimeFormat.forPattern("MM/dd/yyyy")
                              .withLocale(Locale.US);
    
            LocalDate date = formatter.parseLocalDate(text);
            System.out.println(date);
        }    
    }
    

    Once you’ve got a LocalDate, if you want to find out the instant at which that day started in a particular time zone, you can use LocalDate.toDateTimeAtStartOfDay(DateTimeZone).

    • 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 in this format - DD-MM-YYYY this validates that successfully:
I have a date in String format, mm/dd/yyyy I want to convert this to
I am have a string named begin_date which contain date in the format dd.mm.yyyy
i have the date in a string format like so '11/2/2009' (m/d/yyyy) I need
I have encountered a very weird behavior while using SimpleDateFormat for parsing a string
I have date in string format in the table in yyyy-mm-dd format. I want
I have a date that is stored as a string in the format YYYYDDMM.
i have a date entry in yyyy-mm-dd format in mysql database. Using php i
I have a string date like this: $date = 23/12/2011;//format: dd/mm/yyyy. I need each
I have a problem that I have Date String in the format 2011-09-28T10:33:53.694+0000. I

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.