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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:20:22+00:00 2026-05-20T01:20:22+00:00

I convert two types of Strings to an ISO format using SimpleDateFormat for parsing

  • 0

I convert two types of Strings to an ISO format using SimpleDateFormat for parsing and org.apache.commons.lang.time.DateFormatUtils for formatting (since they provide a ISO formatter out-of-the-box).

The pattern Strings for parsing are M/d/y H:m and d.M.y H:m. A typical String to convert may look either like 4/14/2009 11:22 or 4.14.2009 11:22. I initialize the parsers as follows:

SimpleDateFormat SLASH = new SimpleDateFormat(PATTERN_S, Locale.getDefault());
SimpleDateFormat DOT = new SimpleDateFormat(PATTERN_D, Locale.getDefault()); 

I get the the formatter:

  FastDateFormat isoFormatter = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT

After creating a Date from the parsed String:

Date date = FORMAT_SLASH.parse(old);

it is formatted for output:

isoFormatter.format(date)

The strange thing is : when a String with slashes was converted, the output looks like 2009-04-14T11:42:00+01:00 (which is correct) but when a String with dots was converted, the output looks like 2010-02-14T11:42:00+02:00, shifting my timezone to somewhere between Finland and South Africa, the year to 2010 and the month to february

What is going wrong here and why?

EDIT : changed the output strings to match real output (damn you, cut-n-paste). The reason was the interchanged M and d in the pattern strings that I failed to notice. 14 seems to be a perfecty valid month – its next year’s february and even non-lenient settings can’t force the formatter to reject it. The timeshift issue is resolved and the reason for the TimeZone change is provided by Jim Garrison. Thanks Ahmad and Jim

  • 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-20T01:20:23+00:00Added an answer on May 20, 2026 at 1:20 am

    Your dot pattern is d.M.y H:m while your example shows that you meant M.d.y H:m, I supposed this would throw a ParseException, but it doesn’t and it causes timezone issues.

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

Sidebar

Related Questions

How do I properly convert two columns from SQL (2008) using Linq into a
If I want to convert between two Enum types, the values of which, I
.NET supports two types of string formatting. I'm in a situation where existing configuration
So, I have two types at the moment: const unsigned char* unencrypted_data_char; string unencrypted_data;
I need to cast, in the better way, two objects of two types of
I'm using MVVM, in case it makes a difference. My MainWindowViewModel has two DependencyProperties,
So I have two custom complex types like this (oversimplified for this example): public
I need to convert a decimal to a string with N decimals (two or
So I'm trying some code out to convert numbers into strings. However, I noticed
I'm trying to convert a two-dimensional array into a structured array with named fields.

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.