Package com.itextpdf.commons.utils
Class DateTimeUtil
java.lang.Object
com.itextpdf.commons.utils.DateTimeUtil
This file is a helper class for internal usage only. Be aware that its API and functionality may be changed in future.
-
Method Summary
Modifier and TypeMethodDescriptionstatic CalendaraddDaysToCalendar(Calendar calendar, int days) Adds the specified amount of days to the given calendar field.static DateaddDaysToDate(Date date, int days) Adds the specified amount of days to the given date.static DateaddMillisToDate(Date date, long millis) Adds provided number of milliseconds to the Date.static DateaddYearsToDate(Date date, int years) Adds the specified amount of years to the given date.static StringdateToString(Calendar date) ConvertsCalendardate to string of "yyyy.MM.dd HH:mm:ss z" format.static StringFormat passing date with specified pattern.static StringformatWithDefaultPattern(Date date) Format passing date with default yyyy-MM-dd pattern.static CalendargetCalendar(Date date) Gets the date asCalendar.static CalendarGets a defaultGregorianCalendar.static DateGets current time consistently.static longgetCurrentTimeZoneOffset(Date date) Gets the offset of time zone from UTC at the specified date.static longgetRelativeTime(Date date) Gets the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by specified date.static doublegetUtcMillisFromEpoch(Calendar calendar) Gets theCalendaras UTC milliseconds from the epoch.static booleanDefines if date is in past.static DateParses passing date with specified format.static DateParses passing date with default yyyy-MM-dd pattern.
-
Method Details
-
getUtcMillisFromEpoch
Gets theCalendaras UTC milliseconds from the epoch.- Parameters:
-
calendar- the calendar to be converted to millis - Returns:
- the date as UTC milliseconds from the epoch
-
getCalendar
Gets the date asCalendar. -
getCurrentTimeCalendar
Gets a defaultGregorianCalendar.- Returns:
-
a default
GregorianCalendarusing the current time in the default time zone with the default locale
-
getCurrentTimeDate
Gets current time consistently.- Returns:
- the time at which it was allocated, measured to the nearest millisecond
-
addDaysToCalendar
Adds the specified amount of days to the given calendar field.- Parameters:
-
calendar- the calendar field where to add -
days- the amount of days to be added - Returns:
- the time at which it was allocated, measured to the nearest millisecond
-
isInPast
Defines if date is in past.- Parameters:
-
date- the date to be compared with current date - Returns:
-
trueif given date is in past,falseinstead
-
getRelativeTime
Gets the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by specified date.- Parameters:
-
date- the specified date to get time - Returns:
- the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by the specified date
-
addMillisToDate
Adds provided number of milliseconds to the Date. -
addDaysToDate
Adds the specified amount of days to the given date.- Parameters:
-
date- the specified date to add -
days- the amount of days to be added - Returns:
-
a
Dateobject representing the calendar's time value (millisecond offset from the Epoch)
-
addYearsToDate
Adds the specified amount of years to the given date.- Parameters:
-
date- the specified date to add -
years- the amount of years to be added - Returns:
-
a
Dateobject representing the calendar's time value (millisecond offset from the Epoch)
-
parseWithDefaultPattern
Parses passing date with default yyyy-MM-dd pattern.- Parameters:
-
date- is date to be parse - Returns:
- parse date
-
parse
Parses passing date with specified format.- Parameters:
-
date- the date to be parsed -
format- the format of parsing the date - Returns:
- parsed date
-
formatWithDefaultPattern
Format passing date with default yyyy-MM-dd pattern.- Parameters:
-
date- the date to be formatted - Returns:
- formatted date
-
format
Format passing date with specified pattern.- Parameters:
-
date- date to be formatted -
pattern- pattern for format - Returns:
- formatted date
-
getCurrentTimeZoneOffset
Gets the offset of time zone from UTC at the specified date.- Parameters:
-
date- the date represented in milliseconds since January 1, 1970 00:00:00 GMT - Returns:
- the offset of time zone from UTC at the specified date adjusted with the amount of daylight saving.
-
dateToString
ConvertsCalendardate to string of "yyyy.MM.dd HH:mm:ss z" format.- Parameters:
-
date- to convert. - Returns:
- string date value.
-