All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.alantea.swing.misc.TimeStamp Maven / Gradle / Ivy

package net.alantea.swing.misc;

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

import net.alantea.utils.MultiMessages;

@SuppressWarnings("deprecation")
public class TimeStamp implements Comparable
{
   private static SimpleDateFormat dateFormat;
   
   private Date date = new Date();

   public TimeStamp()
   {
   }
   
   public TimeStamp(int hour, int minute)
   {
      date.setHours(hour);
      date.setMinutes(minute);
   }
   
   public TimeStamp(int year, int month, int day)
   {
      date.setYear(year);
      date.setMonth(month);
      date.setDate(day);
   }
   
   public TimeStamp(int year, int month, int day, int hour, int minute)
   {
      date.setYear(year);
      date.setMonth(month);
      date.setDate(day);
      date.setHours(hour);
      date.setMinutes(minute);
   }

   public TimeStamp(Date date)
   {
      this.date.setTime(date.getTime());
   }

   public void setDate(Date date)
   {
      this.date.setTime(date.getTime());
   }

   public Date getDate()
   {
      return date;
   }

   public int getYear()
   {
      return date.getYear();
   }

   public void setYear(int year)
   {
      date.setYear(year);
   }

   public int getMonth()
   {
      return date.getMonth();
   }

   public void setMonth(int month)
   {
      date.setMonth(month);
   }

   public int getDay()
   {
      return date.getDate();
   }

   public void setDay(int day)
   {
      date.setDate(day);
   }

   public int getHour()
   {
      return date.getHours();
   }

   public void setHour(int hour)
   {
      date.setHours(hour);
   }

   public int getMinute()
   {
      return date.getMinutes();
   }

   public void setMinute(int minute)
   {
      date.setMinutes(minute);
   }
   
   public long getTime()
   {
      return getDate().getTime();
   }

   @Override
   public int compareTo(TimeStamp target)
   {
      if (target instanceof TimeStamp)
      {
         return date.compareTo(target.getDate());
      }
      return 1;
   }
   
   @Override
   public String toString()
   {
      if (dateFormat == null)
      {
         String datePattern = MultiMessages.get("Date.format");
         if ((datePattern == null) || (datePattern.contentEquals("Date.format")))
         {
            datePattern = "dd/MM/yyyy HH:mm";
         }
         dateFormat = new SimpleDateFormat(datePattern);
      }
      String date = dateFormat.format(getDate());
      return date;
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy