0 votes

how to remove the time from the date in java?

I have a variable of type Date called fechaElab and I use it in the value of a p:Calendar of primefaces

<p:calendar id="mask"  pattern="dd/MM/yyyy" mask="true" locale="es" value="#{Registro.datosVO.fechaElab}"

Then when I select any date, I get the following message TESTING DATE AWed Feb 14 00:00:00 CST 2018 and it always shows the same time, so what I want is to remove the time. How can I do it?

0 votes

Have you tried calendar.date calendar.year?


SoftMolina Points 1513

In your database the field must be of type date() you probably have it as a timestamp with time zone in this case even if you format the date it will always put the time in zeros 00:00:00, and if you can't change the data type in the database then when you retrieve the date you can do a SimpleDateFormat for example:

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FormateDate {

    public static void main(String[] args) throws ParseException {
        String date_s = "2011-02-19 00:00:00.0";

        SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        Date date = dt.parse(date_s);

        SimpleDateFormat dt1 = new SimpleDateFormat("yyyy-MM-dd");



Raul Cacacho Points 2118

So that it only saves you the date you have to do the following:

  • dateElab must be Date() in java
  • dateElab has to be mapped as Date
  • in the database Date no datetime "this depends on which database you are using".


Klaimmore Points 3568

A java.util.Date represents the milliseconds that have passed since a date called epoch (01/01/1970 00:00:00 GMT).

Therefore, milliseconds is its accuracy. It will depend on your database engine the exact type of storage and with what precision date, datetime, datetime with timezone.

If you want to display that date without the time details, then you have to specify a display format with SimpleDateFormat for example.


HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by: