java - 如何在同一输入日期上添加日期和时间?

标签 java oracle-adf data-conversion

如果添加日期则输入时间默认修改为 01/01/1970 08:00:00 提交期间

例如:
DispDeb = 02/08/2019DispFin 02/08/2019 但时间为 DispDeb 08:00DispFin 12: 00

我的问题

如果在 DispDeb 02/08/2019 中添加日期,并在 inputText 中添加 Time 08:00 更改我在 DispDebDispFin 中的日期,并在我的提交中添加到表中 DispDeb 01/01/1970 08 :00DispFin 01/01/1970 12:00 错误javax.DateTimeConverter转换器

<af:inputDate value="#{bindings.DispDeb.inputValue}"
                                         binding="#{pageFlowScope.PlaningCalBean.dateDebvalue}"
                                                   id="id1"    label="#{bindings.DispDeb.hints.label}" contentStyle="width:100px;" >
                                             <af:convertDateTime pattern="dd/MM/yyyy"/>
                                         </af:inputDate>'
                                        <af:inputText label="Heure Début" id="it4" value="#{bindings.DispDeb.inputValue}"
                                                       contentStyle="width:50px;text-align:center;"
                                                      binding="#{pageFlowScope.PlaningCalBean.heursdateDebvalue}">
                                             <af:convertDateTime pattern="HH:mm"/>
                                       </af:inputText>


`


`

`    public String savegarde() throws ParseException {
        // Add event code here...
        String DateDebut = null , DateDebHeurs = null , docDatesHeursFin = null ;


        SimpleDateFormat ft = new SimpleDateFormat("HH:mm:ss");
        DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
        BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();

           DateDebut = formatter.format(this.getDateDebvalue().getValue());
           DateDebHeurs = ft.format(this.getHeursdateDebvalue().getValue());
           docDatesHeursFin = ft.format(this.getHeursdatefinvalue().getValue());




                        int year=Integer.parseInt(DateDebut.split("/")[2]);
                        int month=Integer.parseInt(DateDebut.split("/")[1]);
                        int day=Integer.parseInt(DateDebut.split("/")[0]);

                        Integer  hour =  Integer.parseInt(DateDebHeurs.split(":")[0]);
                        Integer minute = Integer.parseInt(DateDebHeurs.split(":")[1]);
                        Integer second = Integer.parseInt(DateDebHeurs.split(":")[2]);

                        Integer  hours =  Integer.parseInt(docDatesHeursFin.split(":")[0]);
                        Integer minutes = Integer.parseInt(docDatesHeursFin.split(":")[1]);
                        Integer seconds = Integer.parseInt(docDatesHeursFin.split(":")[2]);

                        LocalDateTime dateTimez = LocalDateTime.of(year, month, day, hour, minute, second);
                        LocalDateTime dateTimezFin = LocalDateTime.of(year, month, day, hours, minutes, seconds);
                        System.out.println(dateTimez + " aloooo " + dateTimezFin);
                       Date date= Date.from(dateTimez.atZone(ZoneId.systemDefault()).toInstant());
                       Timestamp ts =new Timestamp(date.getTime()); 


                       Date datez= Date.from(dateTimezFin.atZone(ZoneId.systemDefault()).toInstant());
                       Timestamp tzs =new Timestamp(datez.getTime()); 
                       System.out.println(ts + " aloooo " + tzs);




         oracle.adf.model.AttributeBinding dateDebutattr = (oracle.adf.model.AttributeBinding)bindings.getControlBinding("DispDeb");
        dateDebutattr.setInputValue(ts);


      BindingContainer bindingsss = getBindings();
      OperationBinding operationBindingss = bindingsss.getOperationBinding("Commit");
       operationBindingss.execute();
        return null;
    }``

最佳答案

我不太确定你想从这个问题中做什么,但你可以简化转换

DispDeb = 02/08/2019 and  DispDeb 08:00

像这样:

DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm")
                .withZone(ZoneId.systemDefault());

String date = "2019/12/19";
String time = "12:00";

String dateTime = date + " " + time;

LocalDateTime localDateTime = LocalDateTime.parse(dateTime, DATE_TIME_FORMATTER);
System.out.println(localDateTime);

Timestamp timestamp = Timestamp.valueOf(localDateTime);
System.out.println(timestamp);

希望有帮助

关于java - 如何在同一输入日期上添加日期和时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59392611/

相关文章:

java - Java 中绑定(bind)变量的 SQL 查询需要很长时间

java - GWT 导入 com.google.gwt.user.cellview.client.CellBrowser 问题

模型的Java同步

java - 轻量级 WebLogic 开发环境

javascript - 通过 Flask 将 numpy 数组作为字节从 python 发送到 JS

go - 如何将接口(interface) {} 转换为结构

java - 如何优化 AppEngine Java/JDO 数据存储 put() 以使用更少的写入

java - 在 adf 中以编程方式更新记录,无需任何关键引用

javascript - 使用 Oracle ADF 时,如何设法检测特定输入文本上按下的按键

r - R中的Shapefile到光栅转换?