Here you can find the source of getDateFromCurrentAnd24HRTime(Date current, String hr24Time)
public static Date getDateFromCurrentAnd24HRTime(Date current, String hr24Time) throws ParseException
//package com.java2s; /**//from ww w . j a v a 2s. co m Copyright 2016 Jason Separovic Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import java.text.ParseException; import java.util.Calendar; import java.util.Date; public class Main { public static Date getDateFromCurrentAnd24HRTime(Date current, String hr24Time) throws ParseException { Calendar calendar = Calendar.getInstance(); calendar.setTime(current); int day = calendar.get(Calendar.DAY_OF_MONTH); int month = calendar.get(Calendar.MONTH); int year = calendar.get(Calendar.YEAR); Calendar newCalendar = Calendar.getInstance(); newCalendar.set(Calendar.DAY_OF_MONTH, day); newCalendar.set(Calendar.MONTH, month); newCalendar.set(Calendar.YEAR, year); newCalendar.setTimeZone(calendar.getTimeZone()); String[] hr24TimeBits = hr24Time.split(":"); newCalendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hr24TimeBits[0])); newCalendar.set(Calendar.MINUTE, Integer.parseInt(hr24TimeBits[1])); newCalendar.set(Calendar.SECOND, 0); newCalendar.set(Calendar.MILLISECOND, 0); return newCalendar.getTime(); } }