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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:47:45+00:00 2026-06-01T11:47:45+00:00

Given a String that is simply a day, for example, Thu or Thursday, how

  • 0

Given a String that is simply a day, for example, “Thu” or “Thursday”, how would I get a java.util.Calendar object where the day String represents the closest String to today. In other words, today is Monday, 3/26/29012, so if the String were “Thu”, I would want to form a date that represents “3/29/2012”. If the String passed in is “Mon” and we’re on Monday, I would want today’s date. In this example, “3/26/2012”.

I tried this …

            final DateFormat formatter = new SimpleDateFormat("EEE");
            java.util.Date date = (Date) formatter.parse(dayOfWeekStr);
            final Calendar now = Calendar.getInstance();
            dateCal.set(Calendar.YEAR, now.get(Calendar.YEAR));
            dateCal.set(Calendar.MONTH, now.get(Calendar.MONTH));
            dateCal.setTime(date);  

but it isn’t working. Once I set the date, the year and month results to 1970, January.

  • 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-01T11:47:47+00:00Added an answer on June 1, 2026 at 11:47 am

    I ended up going with

    public static Calendar getNearestDateFromDayString(final String dayOfWeekStr,
            final Calendar startingDay) throws ParseException {
        final DateFormat formatter = new SimpleDateFormat("EEE");
        final java.util.Date date = (Date) formatter.parse(dayOfWeekStr);
        final Calendar result = Calendar.getInstance();
        result.setTime(date);
        result.set(Calendar.YEAR, startingDay.get(Calendar.YEAR));
        result.set(Calendar.MONTH, startingDay.get(Calendar.MONTH));
        result.set(Calendar.HOUR, startingDay.get(Calendar.HOUR));
        result.set(Calendar.MINUTE, startingDay.get(Calendar.MINUTE));
        result.set(Calendar.SECOND, 0);
        java.util.Date today = new java.util.Date();
        while (result.getTimeInMillis() <= today.getTime()) { 
            result.add(Calendar.DATE, 7);
        }   // while
        return result;
    } // getNearestDateFromDayString
    

    If anyone has a more concise solution, I’ll accept that instead.

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

Sidebar

Related Questions

Given a string that isn't too long, what is the best way to read
I've been looking for a way to hash a given string in C# that
What regular expression can I use (if any) to validate that a given string
It is given in the STL reference that string class is in string header,then
I am building a .NET application that given a connection string, at run time,
GIven the fact that I generate a string containing 0 and 1 of a
Given that I have the following WCF service: class LookUpService { public List<County> GetCounties(string
From a string, I need to pull out groups that match a given pattern.
Simple one to start the day, given a Dictionary<string, string> as follows: var myDict
Given a string of JSON data, how can I safely turn that string into

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.