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 Calendar
addDaysToCalendar
(Calendar calendar, int days) Adds the specified amount of days to the given calendar field.static Date
addDaysToDate
(Date date, int days) Adds the specified amount of days to the given date.static Date
addMillisToDate
(Date date, long millis) Adds provided number of milliseconds to the Date.static Date
addYearsToDate
(Date date, int years) Adds the specified amount of years to the given date.static String
dateToString
(Calendar date) ConvertsCalendar
date to string of "yyyy.MM.dd HH:mm:ss z" format.static String
Format passing date with specified pattern.static String
formatWithDefaultPattern
(Date date) Format passing date with default yyyy-MM-dd pattern.static Calendar
getCalendar
(Date date) Gets the date asCalendar
.static Calendar
Gets a defaultGregorianCalendar
.static Date
Gets current time consistently.static long
getCurrentTimeZoneOffset
(Date date) Gets the offset of time zone from UTC at the specified date.static long
getRelativeTime
(Date date) Gets the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by specified date.static double
getUtcMillisFromEpoch
(Calendar calendar) Gets theCalendar
as UTC milliseconds from the epoch.static boolean
Defines if date is in past.static Date
Parses passing date with specified format.static Date
Parses passing date with default yyyy-MM-dd pattern.
-
Method Details
-
getUtcMillisFromEpoch
Gets theCalendar
as 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
GregorianCalendar
using 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:
-
true
if given date is in past,false
instead
-
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
Date
object 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
Date
object 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
ConvertsCalendar
date to string of "yyyy.MM.dd HH:mm:ss z" format.- Parameters:
-
date
- to convert. - Returns:
- string date value.
-