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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:44:14+00:00 2026-05-30T23:44:14+00:00

From an external service I get objects with Date+Time fields as String ‘s in

  • 0

From an external service I get objects with Date+Time fields as String‘s in format 2012-03-07 12:12:23.547 and I need to compare these fields to get a correct order of the objects. I am well aware that I can create Date objects via e.g. SimpleDateFormat(“yyyy-MM-dd HH:mm:ss.SSS”) and compare the two Date‘s to achieve this but my question is if I can rely on a correct sorting order if I compare them as Strings such as String.compareTo(String)? Some light testing gives me the impression that it works but I am wondering if anyone is aware of any scenarios where it would NOT give me the correct result? Also, are there any performance considerations, pros or cons, of comparing String‘s Vs parsing into Dates to compare?

  • 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-30T23:44:15+00:00Added an answer on May 30, 2026 at 11:44 pm

    Assuming the hours are in 24 hour format, then yes, that’s a sortable date/time format – and one of its well-known benefits is that you can sort without actually parsing.

    One downside: if you get bad data, you won’t spot it – you’ll just neatly sort it into the “right” place, ignoring the fact that you’ve been given (say) February 30th.

    If you need the value as a date/time later on, then I’d parse it first and then compare. But if you only need this in terms of ordering, the string comparison may be faster than parsing everything. Worth benchmarking, of course… especially as comparing two strings on the same day will require several characters-worth of checking, whereas if you’ve parsed it once you can then probably just compare long values.

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

Sidebar

Related Questions

I need to consume an external web service from my VB6 program. I want
We can get external IP from this service using Java, C# or VB.NET. But
I have a PHP script that grabs data from an external service and saves
I've built a web part for Sharepoint that retrieves data from an external service.
I Have an internal SOAP Web service that is being called from an external
I'm trying to write a program that reads text from external file (string string
I want to get live currency rates from an external source, so I found
I'm trying to get content from external feeds on my Django web site with
I am sending a HTTP GET request to the web service of an external
I have a Java program and I need to create a Windows Service from

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.