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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:47:44+00:00 2026-06-07T05:47:44+00:00

I am trying to parse a string into a date in the constructor of

  • 0

I am trying to parse a string into a date in the constructor of an object, which we will call Example. Here is the code

private static final SimpleDateFormat sdf = new SimpleDateFormat(
        "yyyy-MM-dd HH:mm:ss");

private long time;

public Example(String date) {
    try {
        this.time = sdf.parse(date).getTime();
    } catch (Exception e) {
        logger.log(Level.WARNING, "Exception while parsing date " + date, e);
    }
}

Now, I am creating these objects in a Tomcat instance (whether that makes any difference or not).

I get the following types of exceptions

Fri Jul 06 15:13:48 EDT 2012 WARNING: Exception while parsing date 2012-07-06 18:57:31
java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
    at java.lang.Long.parseLong(Long.java:431)
    at java.lang.Long.parseLong(Long.java:468)
    at java.text.DigitList.getLong(DigitList.java:177)
    at java.text.DecimalFormat.parse(DecimalFormat.java:1297)
    at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1589)
    at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1311)
    at java.text.DateFormat.parse(DateFormat.java:335)
    at ...
Fri Jul 06 15:13:48 EDT 2012 WARNING: Exception while parsing date 2012-07-06 19:00:07
java.lang.NumberFormatException: multiple points
    at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1082)
    at java.lang.Double.parseDouble(Double.java:510)
    at java.text.DigitList.getDouble(DigitList.java:151)
    at java.text.DecimalFormat.parse(DecimalFormat.java:1302)
    at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1934)
    at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1311)
    at java.text.DateFormat.parse(DateFormat.java:335)
    at ...
Fri Jul 06 15:13:48 EDT 2012 WARNING: Exception while parsing date 2012-07-06 19:13:21
java.lang.ArrayIndexOutOfBoundsException: -1
    at java.text.DigitList.fitsIntoLong(DigitList.java:212)
    at java.text.DecimalFormat.parse(DecimalFormat.java:1295)
    at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1934)
    at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1311)
    at java.text.DateFormat.parse(DateFormat.java:335)
    at ...
Fri Jul 06 15:48:06 EDT 2012 WARNING: Exception while parsing last check string 2012-07-06 19:08:08
java.lang.NumberFormatException: For input string: ".200172E4.200172"
    at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1222)
    at java.lang.Double.parseDouble(Double.java:510)
    at java.text.DigitList.getDouble(DigitList.java:151)
    at java.text.DecimalFormat.parse(DecimalFormat.java:1302)
    at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1589)
    at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1311)
    at java.text.DateFormat.parse(DateFormat.java:335)
    at ...

So it fails for the dates

2012-07-06 18:57:31
2012-07-06 19:00:07
2012-07-06 19:13:21
2012-07-06 19:08:08

However, if I make a unit test I get the following values for time from these strings

1341615451000
1341615607000
1341616401000
1341616088000

So the SimpleDateFormat object does work… but not on the server? I have noticed that this issue occurs near the startup of the server, and then not later on, if that helps at all. Not really sure what to do next.

Using Tomcat 7.0 and Java 1.6 update 32.

  • 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-07T05:47:45+00:00Added an answer on June 7, 2026 at 5:47 am

    SimpleDateFormat is not thread safe, as explained https://www.palantir.com/2007/07/simpledateformat-is-not-thread-safe/
    Sometimes, really strange or non-logical behaviors when using “static” objects comes from concurrency issues

    To resolve such a case, use a new instance each time (It is better than synchronizing, as synchronization can raise a bottleneck issue)

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

Sidebar

Related Questions

Hi i am trying to parse a string into a java.sql.date Here is what
I am trying to parse a timestamp into a human-readable date string, however, I
I'm trying to parse a String into a DateTime object but it seems to
I am trying to parse a json string straight into a managed object. The
I am trying to convert a string into date time format. DateTime.Parse(tempfrmBankDetails.dgvBankDetails.SelectedRows[0].Cells[PaymentDate].Value.ToString(),null); This is
I'm trying to parse a date string into a DateTime variable. I've found out
I'm trying to convert a String date into a Date object like this: DateFormat
I'm trying to parse a SHGetSpecialFolderPath into a string, a System::String^ to be precise.
I am trying to parse user entered string like A12, into a Haskell tuple,
I'm trying to parse a string to a date field in an android application

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.