Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static Date combineDateTime(Date date, Date time) {

        SimpleDateFormat timeF = new SimpleDateFormat("HH-mm");
        SimpleDateFormat dateF = new SimpleDateFormat("DD-MM-yyyy");
        SimpleDateFormat dateTimeF = new SimpleDateFormat("DD-MM-yyyy-HH-mm");

        String dateStr = dateF.format(date);
        String timeStr = timeF.format(time);
        String result = dateStr + "-" + timeStr;

        Date resultDateTime = null;

        try {
            resultDateTime = dateTimeF.parse(result);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return resultDateTime;
    }
}