Package ucar.nc2.time
Class CalendarDate
java.lang.Object
ucar.nc2.time.CalendarDate
- All Implemented Interfaces:
Comparable<CalendarDate>
A Calendar Date. Replaces java.util.Date.
Allows non-standard calendars. Default is Calendar.gregorian.
Always in UTC time zone.
- Since:
- 3/21/11
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doublestatic final doublestatic final doublestatic final doublestatic final doublestatic final doublestatic final CalendarDate -
Method Summary
Modifier and TypeMethodDescriptionadd(double value, CalendarPeriod.Field unit) Deprecated.use CalendarDate add(CalendarPeriod period)add(CalendarPeriod period) intbooleanintlongGet difference between two calendar dates in given Field unitslongGet difference between two calendar dates in millisecsintintGet the hour of day (0-23) field for this chronology.longGets the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00Z.udunits formattinginthashCode()booleanbooleanstatic CalendarDateof(long msecs) Create CalendarDate from msecs since epoch Uses standard Calendar.static CalendarDateCreate CalendarDate from a java.util.Date.static CalendarDateof(Calendar cal, int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute) Get Calendar date from fields.static CalendarDateCreate CalendarDate from msecs since epoch Uses the given Calendar.static CalendarDateparseISOformat(String calendarName, String isoDateString) Get CalendarDate from ISO date stringstatic CalendarDateparseUdunits(String calendarName, String udunits) Get CalendarDate from udunit date stringstatic CalendarDateparseUdunitsOrIso(String calendarName, String isoOrUdunits) Get CalendarDate from ISO date stringstatic CalendarDatepresent()Get a CalendarDate representing the present momentstatic CalendarDatesubtract(CalendarPeriod period) toDate()Get the equivilent java.util.DatetoString()ISO formatted stringtruncate the CalendarDate, by zeroing all the fields that are less than the field.static CalendarDate
-
Field Details
-
UNKNOWN
-
MILLISECS_IN_SECOND
public static final double MILLISECS_IN_SECOND- See Also:
-
MILLISECS_IN_MINUTE
public static final double MILLISECS_IN_MINUTE- See Also:
-
MILLISECS_IN_HOUR
public static final double MILLISECS_IN_HOUR- See Also:
-
MILLISECS_IN_DAY
public static final double MILLISECS_IN_DAY- See Also:
-
MILLISECS_IN_YEAR
public static final double MILLISECS_IN_YEAR- See Also:
-
MILLISECS_IN_MONTH
public static final double MILLISECS_IN_MONTH- See Also:
-
-
Method Details
-
present
Get a CalendarDate representing the present moment- Returns:
- CalendarDate representing the present moment in UTC
-
present
-
of
public static CalendarDate of(Calendar cal, int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute) Get Calendar date from fields. Uses UTZ time zone- Parameters:
cal- calendar to use, or null for defaultyear- any integermonthOfYear- 1-12dayOfMonth- 1-31hourOfDay- 0-23minuteOfHour- 0-59secondOfMinute- 0-59- Returns:
- CalendarDate
-
withDoy
public static CalendarDate withDoy(Calendar cal, int year, int doy, int hourOfDay, int minuteOfHour, int secondOfMinute) -
of
Create CalendarDate from a java.util.Date. Uses standard Calendar.- Parameters:
date- java.util.Date- Returns:
- CalendarDate in UTC
-
of
Create CalendarDate from msecs since epoch Uses standard Calendar.- Parameters:
msecs- milliseconds from 1970-01-01T00:00:00Z- Returns:
- CalendarDate in UTC
-
of
Create CalendarDate from msecs since epoch Uses the given Calendar.- Parameters:
cal- calendar to use, or null for defaultmsecs- milliseconds from 1970-01-01T00:00:00Z- Returns:
- CalendarDate in UTC time zone.
-
parseUdunitsOrIso
Get CalendarDate from ISO date string- Parameters:
calendarName- get Calendar from Calendar.get(calendarName). may be nullisoOrUdunits- ISO or udunits date string- Returns:
- CalendarDate or null if not valid
-
parseISOformat
Get CalendarDate from ISO date string- Parameters:
calendarName- get Calendar from Calendar.get(calendarName). may be nullisoDateString- ISO date string- Returns:
- CalendarDate
-
parseUdunits
Get CalendarDate from udunit date string- Parameters:
calendarName- get Calendar from Calendar.get(calendarName). may be nulludunits- must be value (space) udunits string- Returns:
- CalendarDate
-
getCalendar
-
getMillis
public long getMillis()Gets the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00Z.- Returns:
- the number of milliseconds since 1970-01-01T00:00:00Z
-
compareTo
- Specified by:
compareToin interfaceComparable<CalendarDate>
-
isAfter
-
isBefore
-
equals
-
hashCode
public int hashCode() -
toString
ISO formatted string -
getTimeUnits
udunits formatting- Returns:
- udunits formatted date
-
getHourOfDay
public int getHourOfDay()Get the hour of day (0-23) field for this chronology.- Returns:
- hour of day (0-23)
-
getFieldValue
-
getDayOfMonth
public int getDayOfMonth() -
add
Deprecated.use CalendarDate add(CalendarPeriod period) -
add
-
subtract
-
truncate
truncate the CalendarDate, by zeroing all the fields that are less than the field. So 2013-03-01T19:30 becomes 2013-03-01T00:00 if the field is "day"- Parameters:
fld- set to 0 all fields less than this one- Returns:
- truncated result
-
toDate
Get the equivilent java.util.Date- Returns:
- the equivalent Date
-
getDifferenceInMsecs
Get difference between two calendar dates in millisecs- Parameters:
o- other calendar date- Returns:
- (this minus o) difference in millisecs
-
getDifference
Get difference between two calendar dates in given Field units- Parameters:
o- other calendar date- Returns:
- (this minus o) difference in units of this Field
-
toGregorianCalendar
-