Java Date Convert convertDateTime(String date, String time)

Here you can find the source of convertDateTime(String date, String time)

Description

convert Date Time

License

Open Source License

Declaration

public static long convertDateTime(String date, String time) 

Method Source Code

//package com.java2s;
/**//  ww  w . j av  a  2  s .  co m
 * This file is part of MadCommander, a file manager with two panels.
 *
 * MadCommander is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MadCommander is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MadCommander.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Calendar;
import java.util.GregorianCalendar;

public class Main {
    public static long convertDateTime(String date, String time) {
        Calendar calendar = GregorianCalendar.getInstance();
        if (date != null) {
            String[] dates = date.split("/");

            int day = Integer.valueOf(dates[0]);
            int month = Integer.valueOf(dates[1]) - 1;
            int year = Integer.valueOf(dates[2]);

            calendar.set(Calendar.DATE, day);
            calendar.set(Calendar.MONTH, month);
            calendar.set(Calendar.YEAR, year);
        }

        if (time != null) {
            String[] times = time.split(":");

            int hour = Integer.valueOf(times[0]);
            int minutes = Integer.valueOf(times[1]);

            calendar.set(Calendar.HOUR_OF_DAY, hour);
            calendar.set(Calendar.MINUTE, minutes);
        }

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

Related

  1. convert(Date d)
  2. convertDate(Object obj)
  3. convertDateTimeToSysTime(String sDateTime)
  4. ConvertDateToAge(String date)
  5. convertDateToDoubleTime(Date time)
  6. convertDateToInt(final Date date)