Java Timestamp concatDateAndTime(Timestamp date, Time time)

Here you can find the source of concatDateAndTime(Timestamp date, Time time)

Description

Concats date with time to call the overloaded changeDate method:

License

Open Source License

Declaration

public static Timestamp concatDateAndTime(Timestamp date, Time time) 

Method Source Code

//package com.java2s;
/**//  ww  w.j a  v  a2  s.  co m
 * Exhibit A - UIRF Open-source Based Public Software License.
 * 
 * The contents of this file are subject to the UIRF Open-source Based Public
 * Software License(the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * openelis.uhl.uiowa.edu
 * 
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * 
 * The Original Code is OpenELIS code.
 * 
 * The Initial Developer of the Original Code is The University of Iowa.
 * Portions created by The University of Iowa are Copyright 2006-2008. All
 * Rights Reserved.
 * 
 * Contributor(s): ______________________________________.
 * 
 * Alternatively, the contents of this file marked "Separately-Licensed" may be
 * used under the terms of a UIRF Software license ("UIRF Software License"), in
 * which case the provisions of a UIRF Software License are applicable instead
 * of those above.
 */

import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;

public class Main {
    /**
     * Concats date with time to call the overloaded changeDate method:
     */
    public static Timestamp concatDateAndTime(Timestamp date, Time time) {
        Calendar c;

        if (date == null || time == null)
            return date;

        c = Calendar.getInstance();
        c.setTimeInMillis(date.getTime());
        c.set(Calendar.HOUR_OF_DAY, time.getHours());
        c.set(Calendar.MINUTE, time.getMinutes());
        c.set(Calendar.SECOND, time.getSeconds());

        return new Timestamp(c.getTimeInMillis());
    }

    public static Timestamp concatDateAndTime(Timestamp date, Timestamp time) {
        Calendar c;

        if (date == null || time == null)
            return date;

        c = Calendar.getInstance();
        c.setTimeInMillis(date.getTime());
        c.set(Calendar.HOUR_OF_DAY, time.getHours());
        c.set(Calendar.MINUTE, time.getMinutes());
        c.set(Calendar.SECOND, time.getSeconds());

        return new Timestamp(c.getTimeInMillis());
    }
}

Related

  1. calendarToTimestamp(java.util.Calendar inCal)
  2. calToTimeStamp(Calendar cal)
  3. changeDate(Timestamp date, Integer amount, Integer unit)
  4. checkTimestamp(String sval)
  5. clone(Timestamp original)
  6. convertTS2HHMM(Timestamp timeStamp)
  7. copyOrCreateTimestampNullsafe(Date date)
  8. createDateTimestamp(java.util.Date date)
  9. date2Timestamp(Date date)