JavaDate.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */



  20. package org.openspcoop2.utils.date;

  21. import java.sql.Timestamp;
  22. import java.util.Calendar;
  23. import java.util.Date;
  24. import java.util.GregorianCalendar;

  25. import org.openspcoop2.utils.UtilsException;

  26. /**
  27.  * Classe per la produzione di date utilizzando la data di Java.
  28.  *
  29.  * @author Poli Andrea (apoli@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public class JavaDate implements IDate{

  34.     /**
  35.      * Impostazione delle proprieta' per il DateManager
  36.      */
  37.     @Override
  38.     public void init(java.util.Properties properties) throws UtilsException{}
  39.    
  40.     /**
  41.      * Close il DataManager
  42.      *
  43.      * @throws UtilsException
  44.      */
  45.     @Override
  46.     public void close() throws UtilsException{}
  47.    
  48.     /**
  49.      * Ritorna la data corrente.
  50.      *
  51.      * @return Data corrente
  52.      */
  53.     @Override
  54.     public Date getDate() throws UtilsException{
  55.         return new Date();
  56.     }
  57.    
  58.     /**
  59.      * Ritorna la data corrente in millisecondi da Gennaio 1.4970.
  60.      *
  61.      * @return Data corrente
  62.      */
  63.     @Override
  64.     public long getTimeMillis() throws UtilsException{
  65.         return new Date().getTime();
  66.     }
  67.    
  68.     /**
  69.      * Ritorna la data corrente come timestamp SQL.
  70.      *
  71.      * @return Data corrente
  72.      */
  73.     @Override
  74.     public Timestamp getTimestamp() throws UtilsException{
  75.         return new Timestamp(new Date().getTime());
  76.     }
  77.    
  78.     /**
  79.      * Ritorna la data corrente come Calendar
  80.      *
  81.      * @return Data corrente
  82.      */
  83.     @Override
  84.     public Calendar getCalendar() throws UtilsException{
  85.         Calendar c = new GregorianCalendar();
  86.         c.setTime(this.getDate());
  87.         return c;
  88.     }
  89. }