Java Date Create buildDateTime(String curDate, String curTime, String meridiem)

Here you can find the source of buildDateTime(String curDate, String curTime, String meridiem)

Description

Build the date object according to the date and time value from the page.

License

Open Source License

Parameter

Parameter Description
curDate the date string.
curTime the time string.

Return

A Date object representing the date/time.

Declaration

public static Date buildDateTime(String curDate, String curTime, String meridiem) 

Method Source Code

//package com.java2s;

import java.text.DateFormat;

import java.text.ParseException;

import java.util.Date;

public class Main {
    /**/* ww w  . jav  a 2s.c o  m*/
     * Build the date object according to the date and time value from the page.
     * @param curDate
     * the date string.
     * @param curTime
     * the time string.
     * @return A Date object representing the date/time.
     */
    public static Date buildDateTime(String curDate, String curTime, String meridiem) {
        Date newDate = null;
        if (curDate != null && !"".equals(curDate.trim()) && curTime != null && !"".equals(curTime.trim())) {
            String dateToParse = curDate + " " + curTime + " " + meridiem;
            DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
            try {
                newDate = format.parse(dateToParse);
            } catch (ParseException paex) {
                newDate = null;
            }
        } else if (curDate != null && !"".equals(curDate.trim())) {
            DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT);
            try {
                newDate = format.parse(curDate);
            } catch (ParseException e) {
                newDate = null;
            }
        }

        return newDate;
    }
}

Related

  1. addTimeToDate(Date date, Date time)
  2. buildDate(int y, int m, int d)
  3. buildDate(String dateAsString)
  4. buildDateFormat(final String pattern)
  5. buildDatetime(Date datePart, Date hourMinutePart)
  6. buildDateTimeUTC(Calendar cal)
  7. castToDate(Object value)
  8. create(int year, int month, int date, TimeZone timeZone)
  9. createDate(final Date date)