Java SQL Date From convertToDateTime(java.util.Date date, String time)

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

Description

convert To Date Time

License

Open Source License

Declaration

public static Date convertToDateTime(java.util.Date date, String time) throws ParseException 

Method Source Code


//package com.java2s;

import java.sql.Date;
import java.text.ParseException;
import java.util.Calendar;
import java.util.GregorianCalendar;

import java.util.StringTokenizer;

public class Main {
    public static Date convertToDateTime(java.util.Date date, String time) throws ParseException {

        Calendar calendar = new GregorianCalendar();
        String[] timeArray = getTime(time);
        calendar.setTime(date);/*from w w w . j  av a 2 s  .c  om*/
        calendar.set(Calendar.HOUR, Integer.parseInt(timeArray[0]));
        calendar.set(Calendar.MINUTE, Integer.parseInt(timeArray[1]));

        return new Date(calendar.getTime().getTime());
    }

    private static String[] getTime(String time) {
        String[] timeArray = new String[2];
        StringTokenizer tc = new StringTokenizer(time, ":");

        // Hour
        timeArray[0] = tc.nextToken();

        // Minute
        timeArray[1] = tc.nextToken();

        return timeArray;
    }
}

Related

  1. convertTime(long time)
  2. convertTime(String time)
  3. convertTime2String(long time)
  4. convertTime2TS(long time)
  5. convertTimeToHour(long time)
  6. convertToTime(Date toDate)
  7. convertToTime(java.util.Date date)
  8. getCNTimezone()
  9. getCurAllTime()