Java Date Create createDateTime(Date date, Date time)

Here you can find the source of createDateTime(Date date, Date time)

Description

combine a date (yy/mm/dd) and a time (hh:mm:ss) into a combined timestamp-date containing both date and time.

License

Open Source License

Declaration

public static Date createDateTime(Date date, Date time) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 BSI Business Systems Integration AG.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from w w w  .  j  a  v a  2 s.c om*/
 *     BSI Business Systems Integration AG - initial API and implementation
 ******************************************************************************/

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**
     * combine a date (yy/mm/dd) and a time (hh:mm:ss) into a combined timestamp-date containing both date and time.
     */
    public static Date createDateTime(Date date, Date time) {
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(date);
        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(time);
        cal1.set(Calendar.HOUR_OF_DAY, cal2.get(Calendar.HOUR_OF_DAY));
        cal1.set(Calendar.MINUTE, cal2.get(Calendar.MINUTE));
        cal1.set(Calendar.SECOND, cal2.get(Calendar.SECOND));
        cal1.set(Calendar.MILLISECOND, cal2.get(Calendar.MILLISECOND));
        return cal1.getTime();
    }
}

Related

  1. createDate(int year, int month, int day, int hour, int minute, int second)
  2. createDate(int year, int month, int day, int hour, int minute, int second, int millisecond)
  3. createDateObject(Integer year, Integer month, Integer dayOfMonth, Integer hourOfDay, Integer minute, Integer second, Integer milissecond)
  4. createDates(int yy, int mm, int dd, int hh, int min, int ss)
  5. createDateString(long startDate, long endDate)
  6. createDateTime(int year, int month, int day, int hour, int minute, int second, String timezone)
  7. createFutureDate()
  8. createFutureDate(int min)
  9. createInitialDateQuery(final Date date)