Here you can find the source of buildDateTime(String curDate, String curTime, String meridiem)
Parameter | Description |
---|---|
curDate | the date string. |
curTime | the time string. |
public static Date buildDateTime(String curDate, String curTime, String meridiem)
//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; } }