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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:57:16+00:00 2026-05-27T19:57:16+00:00

I have a question related to conversion/formatting of date. I have a date,say,workDate with

  • 0

I have a question related to conversion/formatting of date.

I have a date,say,workDate with a value, eg: 2011-11-27 00:00:00
From an input textbox, I receive a time value(as String) in the form “HH:mm:ss”, eg: “06:00:00”

My task is to create a new Date,say,newWorkDate, having the same year,month,date as workDate,and time to be the textbox input value.

So in this case, newWorkDate should be equal to 2011-11-27 06:00:00.
Can you help me figure out how this can be achieved using Java?

Here is what I have so far:

    SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
    //Text box input is converted to Date format -what will be the default year,month and date set here?
     Date textBoxTime = df.parse(minorMandatoryShiftStartTimeStr);

     Date workDate = getWorkDate();
     int year = Integer.parseInt(DateHelper.getYYYYMMDD(workDate).substring(0, 4));
     int month = Integer.parseInt(DateHelper.getYYYYMMDD(workDate).substring(4, 6));
     int date = Integer.parseInt(DateHelper.getYYYYMMDD(workDate).substring(6, 8));

     Date newWorkDate = DateHelper.createDate(year, month, day);
    //not sure how to set the textBox time to this newWorkDate.

[UPDATE]: Thx for the help,guys!Here is the updated code based on all your suggestions..Hopefully this will work.:)

 String[] split = textBoxTime.split(":");
             int hour = 0;
               if (!split[0].isEmpty)){ 
               hour = Integer.parseInt(split[0]);}
             int minute = 0;
             if (!split[1].isEmpty()){
             minute = Integer.parseInt(split[1]);}
             int second = 0;
             if (!split[2].isEmpty()){
                second  = Integer.parseInt(split[2]);}

              Calendar cal=Calendar.getInstance();  
              cal.setTime(workDate); 
              cal.set(Calendar.HOUR, hour); 
              cal.set(Calendar.MINUTE, minute);  
              cal.set(Calendar.SECOND, second);  
              Date newWorkDate = cal.getTime(); 
  • 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-27T19:57:16+00:00Added an answer on May 27, 2026 at 7:57 pm

    A couple of hints:

    1. Use a Calendar object to work with the dates. You can set the Calendar from a Date so the way you create the dates textBoxTime and workDate are fine.
    2. Set the values of workDate from textBoxTime using the setXXX methods on Calendar class (make workDate a Calendar)
    3. You can use SimpleDateFormat to format as well as parse. Use this to produce the desired output.

    You should be able to do this with no string parsing and just a few lines of code.

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

Sidebar

Related Questions

I have question related to what is done in SMS application is if i'm
I have a question related to this one . I don't want to do
I have a question related to this one : I'm trying to attach an
I have a question related to understanding of how python dictionaries work. I remember
I have following event class. I have a question related to the Property method
I have a modeling question related to profiles. Firstly, I have looked into using
Another question related to this one . I have a List<SortableObjects> that is the
I have read other related question but i cant really get them to relate
I have seen the related question here: An object with the same key already
Hi I have a Subclipse related question. In SVN when you merge the trunk

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.