Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split Date and Time from a Date to type separately

Tags:

java

jsf

I'd like to do this:

Date meetingDateAndTime;

<h:inputText value="Date"/>
<h:inputText value="Time"/>

Once I got only one attribute Date, is it possible to type Date in an inputText and type Time into another and then merge them together?

like image 274
Gondim Avatar asked Oct 19 '11 12:10

Gondim


People also ask

How do I separate date and time in different cells in Excel?

One of the best ways to Separate a date from a date and time value is by using the INT function. INT function takes an integer from a number and left out the fractional part.

How do you separate the date and time in a single cell?

If a cell contains a combined date and time, you can use the INT function to pull the time value into a separate column. Dates are stored as numbers in Excel, with the decimal portion representing the time.


1 Answers

You could use two DateFormats, one that outputs the Date and one that outputs the Time. SimpleDateFormat

DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
DateFormat dateFormat = new SimpleDateFormat("hh:mm:ss");

Edit: Sorry, I thought you were trying to write two fields from one date not create one date from two fields. What about the following:

DateFormat dateFormat = new SimpleDateFormt("dd-MM-yyyy hh:mm:ss);
String dateString = dateInputText + " " + timeInputText;
Date date = dateFormat.parse(dateString); 
like image 179
John B Avatar answered Sep 29 '22 06:09

John B