Package es.gob.afirma.tsl.utils
Class UtilsDate
- java.lang.Object
-
- es.gob.afirma.tsl.utils.UtilsDate
-
public class UtilsDate extends java.lang.ObjectClass that provides methods for managing dates.
Project:Library for the integration with the services of @Firma, eVisor and TS@.
- Version:
- 1.0, 10/10/2020.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringFORMAT_DATEConstant attribute that represents the date formatyyyy-MM-dd.static java.lang.StringFORMAT_DATE_ADDITIONALConstant attribute that represents the date format"yyyy/MM/dd EEE hh:mm:ss zzzz".static java.lang.StringFORMAT_DATE_DOWNConstant attribute that represents the date formatdd_MM_yyyy.static java.lang.StringFORMAT_DATE_INVERTEDConstant attribute that represents the date format"dd-MM-yyyy".static java.lang.StringFORMAT_DATE_SLASHConstant attribute that represents the date format"dd/MM/yyyy/HH/mm/ss".static java.lang.StringFORMAT_DATE_SMALLConstant attribute that represents the date formatdd/MM/yyyy.static java.lang.StringFORMAT_DATE_TIMEConstant attribute that represents the date formatyyyy-MM-dd HH:mm:ss.static java.lang.StringFORMAT_DATE_TIME_ADDITIONALConstant attribute that represents the date format"yyyy-MM-dd'T'HHmmssZ".static java.lang.StringFORMAT_DATE_TIME_CRL_ISSUE_TIMEConstant attribute that represents the date format"yyyy-MM-dd'T'HH:mm:ss".static java.lang.StringFORMAT_DATE_TIME_FULLConstant attribute that represents the date format"yyyy-MM-dd HH:mm:ss,SSS".static java.lang.StringFORMAT_DATE_TIME_JSONConstant attribute that represents the date format"yyyy-MM-dd'T'HH:mm:ss.SSSXXX".static java.lang.StringFORMAT_DATE_TIME_JUNTAConstant attribute that represents the date formatyyyyMMddHHmmss.static java.lang.StringFORMAT_DATE_TIME_JUNTA_ADDITIONALConstant attribute that represents the date format"yyyyMMddHHmmss.SZ".static java.lang.StringFORMAT_DATE_TIME_MINUTESConstant attribute that represents the date format"dd-MMM-yyyy HH:mm".static java.lang.StringFORMAT_DATE_TIME_MYSQL_HSQLDBConstant attribute that represents the date format"YYYY/MM/DD HH24:MI:SS".static java.lang.StringFORMAT_DATE_TIME_NOTFULLConstant attribute that represents the date format"yyyy-MM-dd HH:mm:ss ZZZZ".static java.lang.StringFORMAT_DATE_TIME_ORACLEConstant attribute that represents the date format"MM/DD/YYYY HH24:MI:SS".static java.lang.StringFORMAT_DATE_TIME_SECONDSConstant attribute that represents the date format"dd-MM-yy_HH-mm-ss".static java.lang.StringFORMAT_DATE_TIME_STANDARDConstant attribute that represents the date format"dd/MM/yyyy HH:mm:ss".static java.lang.StringFORMAT_DATE_TIME_STANDARD_ADDITIONALConstant attribute that represents the date format"dd/MM/yyyy HH:mm:ss.SSS".static java.lang.StringFORMAT_DATE_TIME_TIMESTAMPConstant attribute that represents the date format"yyyy-MM-dd'T'HH:mm:ss'.'static java.lang.StringFORMAT_DATE_TIME_TSLConstant attribute that represents the date format"yyyy-MM-dd'T'HH:mm:ss'Z".static java.lang.StringFORMAT_DATE_TIME_UTCConstant attribute that represents the date format"yyyy-MM-dd'T'HH:mm:ss.SSS".static java.lang.StringFORMAT_DATE_TIME_XML_CONFIGURATIONConstant attribute that represents the date format"yyyy-MM-dd HH:mm:ss.SSS zzz".static java.lang.StringFORMAT_FULLConstant attribute that represents the date formatyyyy-MM-dd EEE HH:mm:ss ZZZZ.static java.lang.StringFORMAT_TIMEConstant attribute that represents the date formatHH:mm:ss.
-
Constructor Summary
Constructors Constructor Description UtilsDate()Constructor method for the class UtilsDate.java.UtilsDate(java.lang.String timezone)Constructor method for the class UtilsDate.java.UtilsDate(java.lang.String dateString, java.lang.String dateFormat)Constructor method for the class UtilsDate.java.UtilsDate(java.util.Calendar c)Constructor method for the class UtilsDate.java.UtilsDate(java.util.Date pFecha)Constructor method for the class UtilsDate.java.UtilsDate(java.util.TimeZone t)Constructor method for the class UtilsDate.java.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDays(int numDays)Method that adds a number of days to the date.java.lang.StringaddDaysToSystemDate(int numDays)Method that adds a number of days to the system date.java.util.DategetDate()Gets the value of the attributedate.static java.util.DategetDateAddingDays(java.util.Date initialDate, int numDays)Method that adds a number of days to certain date.static java.lang.Integer[]getHoursSecondsMinutes(java.lang.Long milliseconds)Method that obtains the value in hours, minutes and seconds of a period in milliseconds.static java.lang.LonggetPeriod(java.lang.Long hourPeriod, java.lang.Long minutePeriod, java.lang.Long secondPeriod)Method that obtains a period in milliseconds.static java.lang.StringgetSystemDate(java.lang.String formato)Method that obtains the current date and time of the system.static java.lang.StringgetSystemDateAddingDays(java.lang.String initialDate, int numDays)Method that adds a number of days to certain date.static java.util.DategetUTCDate(java.lang.String utcDate)Method that obtains a date from a string withUTCformat.static java.lang.StringmodifyFormat(java.lang.String initialDate, java.lang.String originalFormat, java.lang.String newFormat)Method that modifies the format of a date.static java.util.DateparseToPDFDate(java.lang.String value)Method that returns a Date from a string representing a PDF Date conform to the ASN.1 date format.voidsetDate(java.util.Date pFecha)Sets the value of the attributedate.java.lang.StringtoString()java.lang.StringtoString(java.lang.String dateFormat)Method that obtains a string with the value of the date for certain format.static java.lang.StringtoString(java.lang.String dateFormat, java.util.Date dateParam)Method that obtains a string with the value of the date for certain format.java.lang.StringtoString(java.text.SimpleDateFormat simpleDateFormat)Method that obtains a string with the value of the date for certain format.java.lang.StringtoUTCString()Method that obtains a string which represents the date onUTCformat.static java.util.DatetransformDate(java.lang.String initialDate, java.lang.String pattern)Method that obtains a date from a string using a determined pattern.
-
-
-
Field Detail
-
FORMAT_FULL
public static final java.lang.String FORMAT_FULL
Constant attribute that represents the date formatyyyy-MM-dd EEE HH:mm:ss ZZZZ.- See Also:
- Constant Field Values
-
FORMAT_DATE
public static final java.lang.String FORMAT_DATE
Constant attribute that represents the date formatyyyy-MM-dd.- See Also:
- Constant Field Values
-
FORMAT_TIME
public static final java.lang.String FORMAT_TIME
Constant attribute that represents the date formatHH:mm:ss.- See Also:
- Constant Field Values
-
FORMAT_DATE_TIME
public static final java.lang.String FORMAT_DATE_TIME
Constant attribute that represents the date formatyyyy-MM-dd HH:mm:ss.- See Also:
- Constant Field Values
-
FORMAT_DATE_SMALL
public static final java.lang.String FORMAT_DATE_SMALL
Constant attribute that represents the date formatdd/MM/yyyy.- See Also:
- Constant Field Values
-
FORMAT_DATE_DOWN
public static final java.lang.String FORMAT_DATE_DOWN
Constant attribute that represents the date formatdd_MM_yyyy.- See Also:
- Constant Field Values
-
FORMAT_DATE_TIME_STANDARD
public static final java.lang.String FORMAT_DATE_TIME_STANDARD
Constant attribute that represents the date format"dd/MM/yyyy HH:mm:ss".- See Also:
- Constant Field Values
-
FORMAT_DATE_SLASH
public static final java.lang.String FORMAT_DATE_SLASH
Constant attribute that represents the date format"dd/MM/yyyy/HH/mm/ss".- See Also:
- Constant Field Values
-
FORMAT_DATE_TIME_JUNTA
public static final java.lang.String FORMAT_DATE_TIME_JUNTA
Constant attribute that represents the date formatyyyyMMddHHmmss.- See Also:
- Constant Field Values
-
FORMAT_DATE_TIME_JUNTA_ADDITIONAL
public static final java.lang.String FORMAT_DATE_TIME_JUNTA_ADDITIONAL
Constant attribute that represents the date format"yyyyMMddHHmmss.SZ".- See Also:
- Constant Field Values
-
FORMAT_DATE_TIME_ADDITIONAL
public static final java.lang.String FORMAT_DATE_TIME_ADDITIONAL
Constant attribute that represents the date format"yyyy-MM-dd'T'HHmmssZ".- See Also:
- Constant Field Values
-
FORMAT_DATE_TIME_FULL
public static final java.lang.String FORMAT_DATE_TIME_FULL
Constant attribute that represents the date format"yyyy-MM-dd HH:mm:ss,SSS".- See Also:
- Constant Field Values
-
FORMAT_DATE_INVERTED
public static final java.lang.String FORMAT_DATE_INVERTED
Constant attribute that represents the date format"dd-MM-yyyy".- See Also:
- Constant Field Values
-
FORMAT_DATE_TIME_STANDARD_ADDITIONAL
public static final java.lang.String FORMAT_DATE_TIME_STANDARD_ADDITIONAL
Constant attribute that represents the date format"dd/MM/yyyy HH:mm:ss.SSS".- See Also:
- Constant Field Values
-
FORMAT_DATE_TIME_MINUTES
public static final java.lang.String FORMAT_DATE_TIME_MINUTES
Constant attribute that represents the date format"dd-MMM-yyyy HH:mm".- See Also:
- Constant Field Values
-
FORMAT_DATE_TIME_NOTFULL
public static final java.lang.String FORMAT_DATE_TIME_NOTFULL
Constant attribute that represents the date format"yyyy-MM-dd HH:mm:ss ZZZZ".- See Also:
- Constant Field Values
-
FORMAT_DATE_TIME_UTC
public static final java.lang.String FORMAT_DATE_TIME_UTC
Constant attribute that represents the date format"yyyy-MM-dd'T'HH:mm:ss.SSS".- See Also:
- Constant Field Values
-
FORMAT_DATE_ADDITIONAL
public static final java.lang.String FORMAT_DATE_ADDITIONAL
Constant attribute that represents the date format"yyyy/MM/dd EEE hh:mm:ss zzzz".- See Also:
- Constant Field Values
-
FORMAT_DATE_TIME_SECONDS
public static final java.lang.String FORMAT_DATE_TIME_SECONDS
Constant attribute that represents the date format"dd-MM-yy_HH-mm-ss".- See Also:
- Constant Field Values
-
FORMAT_DATE_TIME_ORACLE
public static final java.lang.String FORMAT_DATE_TIME_ORACLE
Constant attribute that represents the date format"MM/DD/YYYY HH24:MI:SS".- See Also:
- Constant Field Values
-
FORMAT_DATE_TIME_MYSQL_HSQLDB
public static final java.lang.String FORMAT_DATE_TIME_MYSQL_HSQLDB
Constant attribute that represents the date format"YYYY/MM/DD HH24:MI:SS".- See Also:
- Constant Field Values
-
FORMAT_DATE_TIME_XML_CONFIGURATION
public static final java.lang.String FORMAT_DATE_TIME_XML_CONFIGURATION
Constant attribute that represents the date format"yyyy-MM-dd HH:mm:ss.SSS zzz".- See Also:
- Constant Field Values
-
FORMAT_DATE_TIME_CRL_ISSUE_TIME
public static final java.lang.String FORMAT_DATE_TIME_CRL_ISSUE_TIME
Constant attribute that represents the date format"yyyy-MM-dd'T'HH:mm:ss".- See Also:
- Constant Field Values
-
FORMAT_DATE_TIME_TIMESTAMP
public static final java.lang.String FORMAT_DATE_TIME_TIMESTAMP
Constant attribute that represents the date format"yyyy-MM-dd'T'HH:mm:ss'.'SSS'Z'".- See Also:
- Constant Field Values
-
FORMAT_DATE_TIME_JSON
public static final java.lang.String FORMAT_DATE_TIME_JSON
Constant attribute that represents the date format"yyyy-MM-dd'T'HH:mm:ss.SSSXXX".- See Also:
- Constant Field Values
-
FORMAT_DATE_TIME_TSL
public static final java.lang.String FORMAT_DATE_TIME_TSL
Constant attribute that represents the date format"yyyy-MM-dd'T'HH:mm:ss'Z".- See Also:
- Constant Field Values
-
-
Constructor Detail
-
UtilsDate
public UtilsDate()
Constructor method for the class UtilsDate.java.
-
UtilsDate
public UtilsDate(java.util.Date pFecha)
Constructor method for the class UtilsDate.java.- Parameters:
pFecha- Parameter that represents the value of the date.
-
UtilsDate
public UtilsDate(java.util.Calendar c)
Constructor method for the class UtilsDate.java.- Parameters:
c- Parameter that represents the object to set the value of the date and the time zone offset.
-
UtilsDate
public UtilsDate(java.util.TimeZone t)
Constructor method for the class UtilsDate.java.- Parameters:
t- Parameter that represents the time zone offset.
-
UtilsDate
public UtilsDate(java.lang.String timezone)
Constructor method for the class UtilsDate.java.- Parameters:
timezone- Parameter that represents the identifier for the time zone offset.
-
UtilsDate
public UtilsDate(java.lang.String dateString, java.lang.String dateFormat) throws java.text.ParseExceptionConstructor method for the class UtilsDate.java.- Parameters:
dateString- Parameter that represents the value of the date.dateFormat- Parameter that represents the format used for the date.- Throws:
java.text.ParseException- If the method fails.
-
-
Method Detail
-
toString
public final java.lang.String toString(java.lang.String dateFormat)
Method that obtains a string with the value of the date for certain format.- Parameters:
dateFormat- Parameter that represents the format to apply for the date.- Returns:
- a string with the value of the date for certain format.
-
toString
public static final java.lang.String toString(java.lang.String dateFormat, java.util.Date dateParam)Method that obtains a string with the value of the date for certain format.- Parameters:
dateFormat- Parameter that represents the format to apply for the date.dateParam- Date to be transform to String- Returns:
- a string with the value of the date for certain format.
-
toString
public final java.lang.String toString(java.text.SimpleDateFormat simpleDateFormat)
Method that obtains a string with the value of the date for certain format.- Parameters:
simpleDateFormat- Parameter that represents the concrete object for formatting and parsing the date in a locale-sensitive manner.- Returns:
- a string with the value of the date for certain format.
-
toUTCString
public final java.lang.String toUTCString()
Method that obtains a string which represents the date onUTCformat.- Returns:
- the string on
UTCformat.
-
getUTCDate
public static java.util.Date getUTCDate(java.lang.String utcDate) throws java.text.ParseExceptionMethod that obtains a date from a string withUTCformat.- Parameters:
utcDate- Parameter that represents the string withUTCformat.- Returns:
- the date.
- Throws:
java.text.ParseException- If the method fails.
-
getSystemDate
public static java.lang.String getSystemDate(java.lang.String formato)
Method that obtains the current date and time of the system.- Parameters:
formato- Parameter that represents the format used to obtain the date.- Returns:
- the current date and hour of the system in the input format.
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- See Also:
Object.toString()
-
getDate
public final java.util.Date getDate()
Gets the value of the attributedate.- Returns:
- the value of the attribute
date.
-
setDate
public final void setDate(java.util.Date pFecha)
Sets the value of the attributedate.- Parameters:
pFecha- The value for the attributedate.
-
addDays
public final void addDays(int numDays)
Method that adds a number of days to the date.- Parameters:
numDays- Parameter that represents the number of days to add.
-
modifyFormat
public static java.lang.String modifyFormat(java.lang.String initialDate, java.lang.String originalFormat, java.lang.String newFormat) throws java.text.ParseExceptionMethod that modifies the format of a date.- Parameters:
initialDate- Parameter that represents the date.originalFormat- Parameter that represents the original format.newFormat- Parameter that represents the new format.- Returns:
- a string that represents the date with the new format.
- Throws:
java.text.ParseException- If the method fails.
-
addDaysToSystemDate
public final java.lang.String addDaysToSystemDate(int numDays) throws java.text.ParseExceptionMethod that adds a number of days to the system date.- Parameters:
numDays- Parameter that represents the number of days to add.- Returns:
- a string that represents the date returned on format
yyyy-mm-dd. - Throws:
java.text.ParseException- If the method fails.
-
getSystemDateAddingDays
public static java.lang.String getSystemDateAddingDays(java.lang.String initialDate, int numDays) throws java.text.ParseExceptionMethod that adds a number of days to certain date.- Parameters:
initialDate- Parameter that represents the date to add the days. It's a string withYYYYMMDDformat.numDays- Parameter that represents the number of days to add.- Returns:
- a string that represents the date returned on format
yyyyMMDD. - Throws:
java.text.ParseException- If the method fails.
-
getDateAddingDays
public static java.util.Date getDateAddingDays(java.util.Date initialDate, int numDays)Method that adds a number of days to certain date.- Parameters:
initialDate- Parameter that represents the date to add the days.numDays- Parameter that represents the number of days to add.- Returns:
- a Date with diasAdd more.
-
transformDate
public static java.util.Date transformDate(java.lang.String initialDate, java.lang.String pattern) throws java.text.ParseExceptionMethod that obtains a date from a string using a determined pattern.- Parameters:
initialDate- Parameter that represents the string to transform in date.pattern- Parameter that represents the pattern used to generate the date.- Returns:
- a date from a string using a determined pattern.
- Throws:
java.text.ParseException- If the method fails.
-
parseToPDFDate
public static java.util.Date parseToPDFDate(java.lang.String value)
Method that returns a Date from a string representing a PDF Date conform to the ASN.1 date format. This consists of D:YYYYMMDDHHmmSSOHH'mm' where everything before and after YYYY is optional.- Parameters:
value- Parameter that represents the PDF Date.- Returns:
- a wellformed Date if the input param is valid, or null in another case.
-
getPeriod
public static java.lang.Long getPeriod(java.lang.Long hourPeriod, java.lang.Long minutePeriod, java.lang.Long secondPeriod)Method that obtains a period in milliseconds.- Parameters:
hourPeriod- Parameter that represents the hour.minutePeriod- Parameter that represents the minutes.secondPeriod- Parameter that represents the seconds.- Returns:
- the period in milliseconds or
nullif some of the values.
-
getHoursSecondsMinutes
public static java.lang.Integer[] getHoursSecondsMinutes(java.lang.Long milliseconds)
Method that obtains the value in hours, minutes and seconds of a period in milliseconds.- Parameters:
milliseconds- Parameter that represents the period in milliseconds.- Returns:
- an array where the first position is the value of the hour (24-hour), the second position is the value of the minutes and the third position is the value of the minutes.
-
-