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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:55:43+00:00 2026-05-26T12:55:43+00:00

I’d like to parse given date by user but with a specific format :

  • 0

I’d like to parse given date by user but with a specific format : the day name of the week.

So far, here’s what I did :

SimpleDateFormat format = new SimpleDateFormat("E", Locale.ENGLISH);

try {
    Date date = format.parse ("Friday");
    Calendar calendar = format.getCalendar();
    calendar.add(Calendar.WEEK_OF_YEAR, 1);
    return calendar.getTime();
}
catch (ParseException pe) {
    return null;
}

But this returns me :

2 janv. 1970 00:00:00

I’d like it to return me the future friday (in our timelapse, 4 nov. 2011)

How can I do ?

  • 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-26T12:55:43+00:00Added an answer on May 26, 2026 at 12:55 pm

    Parse just the day, put that into a Calendar so that you can find the day of the week, then create another calendar based on the current date so that you can set the day of week:

    currentCalendar.set(Calendar.DAY_OF_WEEK,
                        parsedCalendar.get(Calendar.DAY_OF_WEEK));
    

    Note that that won’t necessarily put it into the future – it’ll set the day within the current week. So you may want to add a week afterwards, if you want to ensure that it’s really in the future:

    // Assume we've already done all the parsing
    int dayOfWeek = parsedCalendar.get(Calendar.DAY_OF_WEEK);
    
    long now = System.currentTimeMillis();
    Calendar currentCalendar = Calendar.getInstance();
    currentCalendar.setTimeInMillis(now);
    currentCalendar.set(Calendar.DAY_OF_WEEK, dayOfWeek);
    if (currentCalendar.getTimeInMillis() < now) {
        currentCalendar.add(Calendar.DAY_OF_MONTH, 7);
    }
    

    (You should check what behaviour you want if the current day of week is the same as the parsed one…)

    As an aside, I’d personally recommend using Joda Time for all serious date and time work in Java. It’s a much nicer API.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I need to clean up various Word 'smart' characters in user input, including but
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have some data like this: 1 2 3 4 5 9 2 6
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the

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.