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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:23:45+00:00 2026-06-13T21:23:45+00:00

Assume an application that parses thousands of date strings per second using some already

  • 0

Assume an application that parses thousands of date strings per second using some already known SimpleDateFormat patterns. The application needs to decide dynamically whether each such date pattern has a timezone, i.e. whether the date pattern string contains, anywhere in it and unquoted, the letters Z or X, in either upper case or lower case (i.e., 4 symbols in total).

Examples of such date patterns are:

  • yyyy/MM/dd HH:mm:ss.SSS Z // Timezone (not quoted Z symbol)
  • yyyy/MM/dd HH:mm:ss.SSS’Z’ // No timezone (quoted Z symbol)
  • EEE MMM dd HH:mm:ss x yyyy // Timezone (not quoted x symbol)
  • EEE MMM dd HH:mm:ss’x’yyyy // No timezone (quoted x symbol)

One way of doing this is by using the indexOf() method of the String class, but this means running the method 4 times on each date pattern (or 2, if the date pattern string is converted to upper or lower case beforehand), plus checking whether the timezone symbol is quoted (in which case the pattern does not actually have a timezone).

The other choice is using a java regular expression, like

String date = ... // Get a SimpleDateFormat pattern

Pattern timezone = Pattern.compile("[^ZzXx]+[^'\"][ZzXx]{1}.*");

if (timezone.matcher(date).matches())
{
    // The date pattern does have a timezone
}

Is there a faster version for the above regular expression, i.e., for

  • "[^ZzXx]+[^'\"][ZzXx]{1}.*"

or any other faster way, in general, for checking whether a SimpleDateFormat pattern does contain a timezone symbol?

  • 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-13T21:23:46+00:00Added an answer on June 13, 2026 at 9:23 pm

    I suggest do it as simple as possible:

    String string = "...";
    
    Pattern p = Pattern.compile("\\b(?<!')([xXzZ])(?!')\\b");
    Matcher m = p.matcher(string);
    if (m.find()) {
      String timeZone = m.group(1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

lets us assume that i am using service or database path in my application,so
All articles I've read about localization of a WinForms application assume that I already
My application has a feature that parses text using a regular expression to extract
Let's assume I have some method that executes CLI application. For example: public string
Assume I have a application that stores data,gets data and processes data and stores
I am working on a Java UI application that uses JDBC. I assume the
assume that i start coding an application from scratch, is the best way to
I am writing a web application on Asp.Net MVC 3. Assume that we have
Assume a multithreaded application scenario, in which every thread acquires some data (one or
I am currently working on an application that parses huge XML files. For each

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.