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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:02:01+00:00 2026-05-21T22:02:01+00:00

my application takes in a string like this 2002-10-15 10:55:01.000000. I need to validate

  • 0

my application takes in a string like this “2002-10-15 10:55:01.000000”. I need to validate that the string is a valid for a db2 timestamp.

How can I do this?

EDIT: This mostly works

     public static boolean isTimeStampValid(String inputString) {
     SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS");
        try {
            format.parse(inputString);
            return true;
        } catch (ParseException e) {
            return false;
        }
     }

The problem is that if I pass it a bad format for milliseconds like “2011-05-02 10:10:01.0av” this will pass validation. I am assuming that since the first millisecond character is valid then it just truncates the rest of the string.

  • 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-21T22:02:02+00:00Added an answer on May 21, 2026 at 10:02 pm

    I’m not exactly sure about the format but you you can play around it and can try something like this

    public static bool isTimeStampValid(String inputString)
    { 
        SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS");
        try{
           format.parse(inputString);
           return true;
        }
        catch(ParseException e)
        {
            return false;
        }
    }
    

    EDIT: if you want to validate for numbers after successful parsing, you could do

           format.parse(inputString);
           Pattern p = Pattern.compile("^\\d{4}[-]?\\d{1,2}[-]?\\d{1,2} \\d{1,2}:\\d{1,2}:\\d{1,2}[.]?\\d{1,6}$");
           return p.matcher(inputString).matches();
    

    instead of

       format.parse(inputString);
       return true;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a simple problem. I have an application that takes a phone number like
Iam developing one application.In that i take the string from array and replace .xml
I have this application written in java to calculate pageranks. And the application takes
I have an application that takes some input and generates configuration files as output.
I have an application that takes a couple of seconds to run. Is it
I have an application which takes time to load so i would like to
I've set up DI with Ninject in my ASP.NET MVC application like this Bind<IRepository>().To<XmlDefaultRepository>().WhenInjectedInto(typeof(PageController)).WithConstructorArgument(contentType,
I'm writing an application that takes HTML pages and parses them to display on
I have an application that takes a dictionary of files (file type, and list
I've written a helper class that takes a string in the constructor and provides

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.