Java SQL Time merge(java.util.Date date, java.util.Date time)

Here you can find the source of merge(java.util.Date date, java.util.Date time)

Description

merge

License

Open Source License

Declaration

private static Timestamp merge(java.util.Date date, java.util.Date time) 

Method Source Code

//package com.java2s;
/*//www . j  a  va 2  s  . c o m
 * Este programa es software libre; usted puede redistribuirlo y/o modificarlo bajo los t?rminos
 * de la licencia "GNU General Public License" publicada por la Fundaci?n "Free Software Foundation".
 * Este programa se distribuye con la esperanza de que pueda ser ?til, pero SIN NINGUNA GARANTIA;
 * vea la licencia "GNU General Public License" para obtener mas informaci?n.
 */

import java.sql.Time;
import java.sql.Timestamp;

import java.util.Calendar;

public class Main {
    private static long currentTimeMillis = 0;
    private static long lastTimeMillis = 0;
    private static long lastTimeMicros = 0;
    private static long lastTimeNanos = 0;
    private static long micros = 0;
    private static long nanos = 0;
    private static final Calendar calendar = Calendar.getInstance();

    private static Timestamp merge(java.util.Date date, java.util.Date time) {
        Calendar d = Calendar.getInstance();
        Calendar t = Calendar.getInstance();
        d.setTimeInMillis(date.getTime());
        t.setTimeInMillis(time.getTime());
        d.set(Calendar.HOUR_OF_DAY, t.get(Calendar.HOUR_OF_DAY));
        d.set(Calendar.MINUTE, t.get(Calendar.MINUTE));
        d.set(Calendar.SECOND, t.get(Calendar.SECOND));
        d.set(Calendar.MILLISECOND, t.get(Calendar.MILLISECOND));
        return new Timestamp(d.getTimeInMillis());
    }

    public static synchronized Time getTime() {
        return currentTime();
    }

    public static synchronized Time getTime(java.util.Date date) {
        if (date == null) {
            return currentTime();
        }
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(date.getTime());
        c.set(Calendar.YEAR, 1970);
        c.set(Calendar.MONTH, Calendar.JANUARY);
        c.set(Calendar.DAY_OF_MONTH, 1);
        return new Time(c.getTimeInMillis());
    }

    public static synchronized Time currentTime() {
        calendar.setTimeInMillis(currentTimeMillis());
        calendar.set(Calendar.YEAR, 1970);
        calendar.set(Calendar.MONTH, Calendar.JANUARY);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        return new Time(calendar.getTimeInMillis());
    }

    public static synchronized long currentTimeMillis() {
        currentTimeMillis = System.currentTimeMillis();
        if (lastTimeMillis < currentTimeMillis) {
            lastTimeMillis = currentTimeMillis;
        } else {
            lastTimeMillis++;
        }
        lastTimeMicros = lastTimeMillis * 1000;
        lastTimeNanos = lastTimeMicros * 1000;
        micros = 0;
        nanos = 0;
        return lastTimeMillis;
    }
}

Related

  1. isDateTime(String val)
  2. isTime(final Class type)
  3. isTime(final PropertyDescriptor pd)
  4. isTime(String val)
  5. isTimeInRange(java.sql.Time start, java.sql.Time end, java.util.Date d)
  6. mergeDateTime(Date date, Time time)
  7. minTime()
  8. minutesToTime(int minutes)
  9. parse(String dateTimeString)