Separate Date and Time objects

前端 未结 2 1024
执念已碎
执念已碎 2021-01-14 08:45

I have a web-form where users can select a date from a calendar pop-up and a time from a dropdown. At the moment I am trying to store the date using a Date object.

相关标签:
2条回答
  • 2021-01-14 09:11

    Try this:

    SimpleDateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");
    SimpleDateFormat timeFormatter = new SimpleDateFormat("HH:mm:ss");
    
    String dateAsString = dateFormatter.format(date);
    String timeAsString = timeFormatter.format(date);
    
    0 讨论(0)
  • 2021-01-14 09:16

    Have a look at the Calendar class. It has all of the methods required to get different "date parts". Also, look at the SimpleDateFormat class in java to format the date in needed way.

    Calendar - http://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html

    SimpleDateFormat - http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

    0 讨论(0)
提交回复
热议问题