从日期中拆分日期和时间以分别键入 [英] Split Date and Time from a Date to type separately

查看:47
本文介绍了从日期中拆分日期和时间以分别键入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这样做:

Date meetingDateAndTime;

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

一旦我只有一个属性Date,是否可以在inputText中键入Date,然后将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?

推荐答案

您可以使用两个DateFormats,一个输出日期,另一个输出时间. SimpleDateFormat

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");

抱歉,我认为您试图从一个日期开始编写两个字段,而不是从两个字段中创建一个日期.那么以下内容:

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); 

这篇关于从日期中拆分日期和时间以分别键入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆