public class JodaTimeUtils extends Object
JodaTime
.Modifier and Type | Field and Description |
---|---|
static org.joda.time.DateTime |
BEGINNING_OF_TIME
This represents a time before all (representable) times.
|
static long |
BEGINNING_OF_TIME_LONG
This represents a time before all (representable) times, in long
representation.
|
static org.joda.time.DateTime |
ENDING_OF_TIME
This represents a time after all (representable) times.
|
static long |
ENDING_OF_TIME_LONG
This represents a time after all (representable) times, in long
representation.
|
static org.joda.time.DateTimeZone |
EST
EST
|
static org.joda.time.DateTimeZone |
GMT
GMT
|
static org.joda.time.DateTime |
ORIGIN
This is the reference time "origin": 1970 January 1, midnight, UTC.
|
Modifier and Type | Method and Description |
---|---|
static double |
fractionOfYear(org.joda.time.LocalDate d1,
org.joda.time.LocalDate d2,
double dayCountInAYear)
Computes a fraction, in years, based on the number of days between two
given dates.
|
static org.joda.time.DateTime |
getDate(int year,
int month,
int day,
org.joda.time.DateTimeZone tz)
Construct a
DateTime instance with year, month, day, and time
zone. |
static org.joda.time.DateTime |
getDateTime(String str)
Construct a
DateTime instance from a string which ends in
TimeZone specification. |
static org.joda.time.DateTime |
getDateTime(String str,
DateFormat format,
org.joda.time.DateTimeZone tz)
Construct a
DateTime instance from a string with no TimeZone
specified. |
static org.joda.time.DateTime |
getFirstInstantAfter(org.joda.time.DateTime startTime,
org.joda.time.DateTimeZone zone,
org.joda.time.LocalTime time)
Get the first instant of time after a given start time.
|
static List<org.joda.time.Interval> |
getIntervals(org.joda.time.DateTime start,
org.joda.time.DateTime end,
org.joda.time.Period period)
Creates a list of intervals between
start and end every
so often. |
static org.joda.time.DateTime |
getLastDayOfMonth(org.joda.time.DateTime t)
Get the last day of the month which contain a time.
|
static org.joda.time.DateTime |
getLastMillisecondOfDay(org.joda.time.DateTime t)
Get the last millisecond the day which contain a time.
|
static int |
getNumberOfPeriodsBetween(org.joda.time.DateTime t1,
org.joda.time.DateTime t2,
org.joda.time.Period period)
Return the number of periods between two times, rounding up.
|
static List<org.joda.time.DateTime> |
getPeriodicInstants(org.joda.time.DateTime startTime,
org.joda.time.Period period,
int nPeriods)
Make a list of periodic time instants.
|
static boolean |
isWeekend(org.joda.time.DateTime time)
Check if the given time is a weekend.
|
static org.joda.time.DateTime |
max(org.joda.time.DateTime t1,
org.joda.time.DateTime t2)
Return the later of two
DateTime instances. |
static org.joda.time.DateTime |
min(org.joda.time.DateTime t1,
org.joda.time.DateTime t2)
Return the earlier of two
DateTime instances. |
static org.joda.time.DateTime |
minusWeekdayPeriod(org.joda.time.DateTime time,
org.joda.time.Period period)
Subtract a weekday-period (i.e., skipping weekends) from a
DateTime . |
static org.joda.time.DateTime |
nextWeekDay(org.joda.time.DateTime time)
Get the next weekday, i.e., skipping Saturdays and Sundays.
|
static org.joda.time.DateTime |
plusWeekdayPeriod(org.joda.time.DateTime time,
org.joda.time.Period period)
Add a weekday-period (i.e., skipping weekends) to a
DateTime . |
static org.joda.time.DateTime |
previousWeekDay(org.joda.time.DateTime time)
Get the previous weekday, i.e., skipping Saturdays and Sundays.
|
public static final org.joda.time.DateTimeZone GMT
public static final org.joda.time.DateTimeZone EST
public static final org.joda.time.DateTime ORIGIN
public static final org.joda.time.DateTime BEGINNING_OF_TIME
public static final long BEGINNING_OF_TIME_LONG
public static final org.joda.time.DateTime ENDING_OF_TIME
public static final long ENDING_OF_TIME_LONG
public static org.joda.time.DateTime getDate(int year, int month, int day, org.joda.time.DateTimeZone tz)
DateTime
instance with year, month, day, and time
zone. It is set to mid-night.year
- yearmonth
- month of the yearday
- day of the monthtz
- time zonepublic static org.joda.time.DateTime getDateTime(String str) throws ParseException
DateTime
instance from a string which ends in
TimeZone specification.str
- the date-time stringDateTime
representationParseException
- if there is an error parsing the stringpublic static org.joda.time.DateTime getDateTime(String str, DateFormat format, org.joda.time.DateTimeZone tz) throws ParseException
DateTime
instance from a string with no TimeZone
specified.str
- the date-time stringformat
- the formattertz
- the time zone; null
if default time zoneDateTime
representationParseException
- if there is an error parsing the stringpublic static org.joda.time.DateTime nextWeekDay(org.joda.time.DateTime time)
time
- a DateTime
public static org.joda.time.DateTime previousWeekDay(org.joda.time.DateTime time)
time
- a DateTime
public static org.joda.time.DateTime plusWeekdayPeriod(org.joda.time.DateTime time, org.joda.time.Period period)
DateTime
. For
example, adding a weekday-period of 2 days and 4 hours to a time instant
representing Thursday 5pm results in a time instant at next Monday 9pm.time
- the original time instantperiod
- the period to be addedDateTime
after the period addedpublic static org.joda.time.DateTime minusWeekdayPeriod(org.joda.time.DateTime time, org.joda.time.Period period)
DateTime
. For example, subtracting a weekday-period of 2 days and
4 hours from a time instant representing Monday 9pm results in a time
instant at previous Thursday 5pm.time
- the original time instantperiod
- the period to be addedDateTime
after the period subtractedpublic static boolean isWeekend(org.joda.time.DateTime time)
time
- a timetrue
if the given time is a weekendpublic static org.joda.time.DateTime min(org.joda.time.DateTime t1, org.joda.time.DateTime t2)
DateTime
instances.t1
- time 1t2
- time 2t1
and t2
public static org.joda.time.DateTime max(org.joda.time.DateTime t1, org.joda.time.DateTime t2)
DateTime
instances.t1
- time 1t2
- time 2t1
and t2
public static int getNumberOfPeriodsBetween(org.joda.time.DateTime t1, org.joda.time.DateTime t2, org.joda.time.Period period)
t1
- time 1t2
- time 2period
- a durationpublic static List<org.joda.time.DateTime> getPeriodicInstants(org.joda.time.DateTime startTime, org.joda.time.Period period, int nPeriods)
startTime
- start timeperiod
- the periodnPeriods
- the number of instants, excluding start timepublic static org.joda.time.DateTime getLastDayOfMonth(org.joda.time.DateTime t)
t
- a timet
is inpublic static org.joda.time.DateTime getLastMillisecondOfDay(org.joda.time.DateTime t)
t
- a timet
is inpublic static List<org.joda.time.Interval> getIntervals(org.joda.time.DateTime start, org.joda.time.DateTime end, org.joda.time.Period period)
start
and end
every
so often.start
- the start timeend
- the end timeperiod
- the period or length of each intervalpublic static org.joda.time.DateTime getFirstInstantAfter(org.joda.time.DateTime startTime, org.joda.time.DateTimeZone zone, org.joda.time.LocalTime time)
startTime
- a start timezone
- the time zonetime
- the time in a daypublic static double fractionOfYear(org.joda.time.LocalDate d1, org.joda.time.LocalDate d2, double dayCountInAYear)
d1
- the start dated2
- the end datedayCountInAYear
- the number of days in a year, e.g., 365 (or 252
for business purpose)Copyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.