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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:45:13+00:00 2026-05-27T00:45:13+00:00

I am trying to parse an SQL date string (ISO 9075) and that uses

  • 0

I am trying to parse an SQL date string (ISO 9075) and that uses microseconds(!) instead of milliseconds, for example

2010-11-22 08:08:08.123456

However, SimpleDateFormat refuses to recognize a pattern like “yyyy-MM-dd HH:mm:ss.SSSSSS” and “yyyy-MM-dd HH:mm:ss.SSS” does not work, either.

The code I am using looks something like this:

String dateString = "2010-11-22 08:08:08.123456";
String pattern = "yyyy-MM-dd HH:mm:ss.SSSSSS";

try
{
    format = new SimpleDateFormat(pattern);
    format.setLenient(false);
    position.setIndex(0);
    Date date1 = format.parse(dateString, position);
    System.out.println("Date 1: " + date1);
    Date date2 = format.parse(dateString);
    System.out.println("Date 2: " + date1);
}
catch (Exception e) // Should not happen
{
    e.printStackTrace();
}

Whichever of the 2 patterns (“.SSS” or “.SSSSSS”) I use, date1 is printer as null, whereas date2 causes a parsing exception (java.text.ParseException: Unparseable date).

  • 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-27T00:45:14+00:00Added an answer on May 27, 2026 at 12:45 am

    Maybe chop the remaining fraction part out of the dateString before parse the date? I have the following

        String dateString = "2010-11-22 08:08:08.123456";
        String fraction = dateString.substring(dateString.length() - 3);
        String formatString = dateString.substring(0, dateString.length() - 3);
        String pattern = "yyyy-MM-dd HH:mm:ss.SSS";
        ParsePosition position = new ParsePosition(0);
    
        try
        {
    
            SimpleDateFormat format = new SimpleDateFormat(pattern);
            format.setLenient(false);
            position.setIndex(0);
            Date date1 = format.parse(formatString, position);          
            System.out.println("Date 1: " + date1);
            System.out.println("Date 1 fraction: " + fraction);
            Date date2 = format.parse(formatString);
            System.out.println("Date 2: " + date2);
            System.out.println("Date 2 fraction: " + fraction);
        }
        catch (Exception e) // Should not happen
        {
            e.printStackTrace();
        }
    

    This allow the date to parse until millisecond precision while you still retain the fraction micro part.

    • 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
Trying to parse an SQL string and pull out the parameters. Ex: select *
I'm trying to write an sql function in Postgresql that will parse a file
Im trying to create a php function that converts a string date to a
Im trying to parse the string located in /proc/stat in a linux filesystem using
I have been trying to parse Java exceptions that appear in a log for
I'm trying to parse an international datetime string similar to: 24-okt-08 21:09:06 CEST So
I'm having issues trying to parse a datetime field that I am returning in
I'm trying to contruct a parser in scala which can parse simple SQL-like strings.
I'm trying to use SQL Server Integration Services (SSIS) to parse an XML file

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.