Package com.itextpdf.commons.utils
Class DateTimeUtil
- java.lang.Object
-
- com.itextpdf.commons.utils.DateTimeUtil
-
public final class DateTimeUtil extends java.lang.Object
This file is a helper class for internal usage only. Be aware that its API and functionality may be changed in future.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
DEFAULT_PATTERN
-
Constructor Summary
Constructors Modifier Constructor Description private
DateTimeUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Calendar
addDaysToCalendar(java.util.Calendar calendar, int days)
Adds the specified amount of days to the given calendar field.static java.util.Date
addDaysToDate(java.util.Date date, int days)
Adds the specified amount of days to the given date.static java.util.Date
addMillisToDate(java.util.Date date, long millis)
Adds provided number of milliseconds to the Date.static java.util.Date
addYearsToDate(java.util.Date date, int years)
Adds the specified amount of years to the given date.static java.lang.String
dateToString(java.util.Calendar date)
ConvertsCalendar
date to string of "yyyy.MM.dd HH:mm:ss z" format.static java.lang.String
format(java.util.Date date, java.lang.String pattern)
Format passing date with specified pattern.static java.lang.String
formatWithDefaultPattern(java.util.Date date)
Format passing date with default yyyy-MM-dd pattern.static java.util.Calendar
getCalendar(java.util.Date date)
Gets the date asCalendar
.static java.util.Calendar
getCurrentTimeCalendar()
Gets a defaultGregorianCalendar
.static java.util.Date
getCurrentTimeDate()
Gets current time consistently.static long
getCurrentTimeZoneOffset(java.util.Date date)
Gets the offset of time zone from UTC at the specified date.static long
getRelativeTime(java.util.Date date)
Gets the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by specified date.static double
getUtcMillisFromEpoch(java.util.Calendar calendar)
Gets theCalendar
as UTC milliseconds from the epoch.private static java.text.DateFormat
initParserSDF(java.lang.String pattern)
static boolean
isInPast(java.util.Date date)
Defines if date is in past.static java.util.Date
parse(java.lang.String date, java.lang.String format)
Parses passing date with specified format.static java.util.Date
parseWithDefaultPattern(java.lang.String date)
Parses passing date with default yyyy-MM-dd pattern.
-
-
-
Field Detail
-
DEFAULT_PATTERN
private static final java.lang.String DEFAULT_PATTERN
- See Also:
- Constant Field Values
-
-
Method Detail
-
getUtcMillisFromEpoch
public static double getUtcMillisFromEpoch(java.util.Calendar calendar)
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
public static java.util.Calendar getCalendar(java.util.Date date)
Gets the date asCalendar
.- Parameters:
date
- the date to be returned asCalendar
- Returns:
- the date as
Calendar
-
getCurrentTimeCalendar
public static java.util.Calendar getCurrentTimeCalendar()
Gets a defaultGregorianCalendar
.- Returns:
- a default
GregorianCalendar
using the current time in the default time zone with the default locale
-
getCurrentTimeDate
public static java.util.Date getCurrentTimeDate()
Gets current time consistently.- Returns:
- the time at which it was allocated, measured to the nearest millisecond
-
addDaysToCalendar
public static java.util.Calendar addDaysToCalendar(java.util.Calendar calendar, int days)
Adds the specified amount of days to the given calendar field.- Parameters:
calendar
- the calendar field where to adddays
- the amount of days to be added- Returns:
- the time at which it was allocated, measured to the nearest millisecond
-
isInPast
public static boolean isInPast(java.util.Date date)
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
public static long getRelativeTime(java.util.Date date)
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
public static java.util.Date addMillisToDate(java.util.Date date, long millis)
Adds provided number of milliseconds to the Date.- Parameters:
date
-Date
date to increasemillis
- number of milliseconds to add- Returns:
- updated
Date
-
addDaysToDate
public static java.util.Date addDaysToDate(java.util.Date date, int days)
Adds the specified amount of days to the given date.- Parameters:
date
- the specified date to adddays
- the amount of days to be added- Returns:
- a
Date
object representing the calendar's time value (millisecond offset from the Epoch)
-
addYearsToDate
public static java.util.Date addYearsToDate(java.util.Date date, int years)
Adds the specified amount of years to the given date.- Parameters:
date
- the specified date to addyears
- the amount of years to be added- Returns:
- a
Date
object representing the calendar's time value (millisecond offset from the Epoch)
-
parseWithDefaultPattern
public static java.util.Date parseWithDefaultPattern(java.lang.String date)
Parses passing date with default yyyy-MM-dd pattern.- Parameters:
date
- is date to be parse- Returns:
- parse date
-
parse
public static java.util.Date parse(java.lang.String date, java.lang.String format)
Parses passing date with specified format.- Parameters:
date
- the date to be parsedformat
- the format of parsing the date- Returns:
- parsed date
-
formatWithDefaultPattern
public static java.lang.String formatWithDefaultPattern(java.util.Date date)
Format passing date with default yyyy-MM-dd pattern.- Parameters:
date
- the date to be formatted- Returns:
- formatted date
-
format
public static java.lang.String format(java.util.Date date, java.lang.String pattern)
Format passing date with specified pattern.- Parameters:
date
- date to be formattedpattern
- pattern for format- Returns:
- formatted date
-
getCurrentTimeZoneOffset
public static long getCurrentTimeZoneOffset(java.util.Date date)
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
public static java.lang.String dateToString(java.util.Calendar date)
ConvertsCalendar
date to string of "yyyy.MM.dd HH:mm:ss z" format.- Parameters:
date
- to convert.- Returns:
- string date value.
-
initParserSDF
private static java.text.DateFormat initParserSDF(java.lang.String pattern)
-
-