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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:52:33+00:00 2026-06-18T00:52:33+00:00

I have time stamp as string 2013-01-28 11:01:56.9. Here 56.9 seconds are mentioned. .9

  • 0

I have time stamp as string “2013-01-28 11:01:56.9”. Here 56.9 seconds are mentioned.

.9 seconds = 900 milliseconds

we can say it’s 9 deci-seconds or 90 centi-seconds

But in java…

String string = "2013-01-28 11:01:56.9";
String pattern = "yyyy-MM-dd hh:mm:ss.S";
SimpleDateFormat formatter = new SimpleDateFormat(pattern);
Date date = formatter.parse(string);
System.out.println(date.getTime());

Output is : 1359388916009

Here 9 is parsed as 009 milliseconds because “S” (Capital-S) is used for milliseconds.

Similarly if .95 seconds are provided as and parsed with “SS” pattern, it gives “095” milliseconds instead of “950” milliseconds.

  • Why java does not provide pattern to parse/format deci-seconds and centi-seconds to make things easier?
  • What is the decent way to do so?
  • 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-18T00:52:34+00:00Added an answer on June 18, 2026 at 12:52 am

    1) Nobody knows why Java does not provide pattern to parse/format deci-seconds and centi-seconds. But I personally suspect, that though your case is very interesting, it is a very particular case of formatting.

    It is hard to imagine such convenient formatting style, which will allow to distinguish case, when . symbol is delimiter between integer and float parts, and when it is just delimiter between date’s parts.

    2) About decent way. It seems to me, that this simple preprocessing should help you:

    public static String preprocess(String date) {
        int pIndex = date.lastIndexOf(".") + 1;
        String millis = date.substring(pIndex);
        for (int i = millis.length(); i < 3; i++)
            millis += "0";
        return date.substring(0, pIndex) + millis;
    }
    

    UPD: It could be written more simple:

    public static String preprocess(String date) {
        String millis = date.substring(date.lastIndexOf(".") + 1);
        for (int i = millis.length(); i < 3; i++)
            date += "0";
        return date;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string variable named $message as below: * Time Stamp: 2012-12-03 16:36:04
How can I convert SQL time using a datetime stamp to milliseconds. I am
I have a time-stamp in milliseconds ( Unix time / time from Epoch )
I have a map of time stamps and some data map<string,double> mymap; how can
I have a time stamp I created with PHP that I would like to
I have a time stamp in my table(2012-04-04 20:44:53) and i would like to
i want to have a time stamp for logs on a Windows Mobile project
In my database I have a time stamp column...which reflects a format like this:
I have a database containing a list of status updates and time stamp. by
I have a XML file like this <?xml version=1.0 encoding=iso-8859-1?>1 <!-- Time-stamp: bibliography.xml 3

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.