public class ErddapCalendar2
extends java.lang.Object
newGCalendar only accounts for daylight savings if your computer is correctly set up. E.g., in Windows, make sure "Start : Control Panel : Date and Time : Time Zone : Automatically adjust clock for daylight savings changes" is checked. Otherwise, the TimeZone used by GregorianCalendar will be for standard time (not including daylight savings time, if any).
Comments about working with Java's GregorianCalendar class:
But this class seeks to simplify things to the more common cases of parsing and formatting using the same time zone as the GregorianCalendar class, and offering GregorianCalendar constructors for Local (with daylight savings if that is what your area does) and Zulu (aka GMT and UTC, which doesn't ever use daylight savings).
A summary of ISO 8601 Date Time formats is at http://www.cl.cam.ac.uk/~mgk25/iso-time.html http://en.wikipedia.org/wiki/ISO_8601 and http://dotat.at/tmp/ISO_8601-2004_E.pdf (was http://www.iso.org/iso/date_and_time_format) and years B.C at http://www.tondering.dk/claus/cal/node4.html#SECTION00450000000000000000
Calendar2 does not use ERA designations. It uses negative year values for B.C years (calendar2Year = 1 - BCYear). Note that BCYears are 1..., so 1 BC is calendar2Year 0 (or 0000), and 2 BC is calendar2Year -1 (or -0001).
Modifier and Type | Field and Description |
---|---|
static int |
MILLISECOND |
static int |
SECONDS_PER_DAY |
static int |
SECONDS_PER_HOUR |
static int |
SECONDS_PER_MINUTE |
static int |
YEAR |
static java.util.TimeZone |
zuluTimeZone |
Constructor and Description |
---|
ErddapCalendar2() |
Modifier and Type | Method and Description |
---|---|
static double |
factorToGetSeconds(java.lang.String units)
This returns the factor to multiply by 'units' data to get seconds
data (e.g., "minutes" returns 60).
|
static double[] |
getTimeBaseAndFactor(java.lang.String tsUnits)
This converts a string "[units] since [isoDate]"
(e.g., "minutes since 1985-01-01") into
a baseSeconds (seconds since 1970-01-01) and a factor ("minutes" returns 60).
|
static java.util.GregorianCalendar |
newGCalendarZulu()
Get a GregorianCalendar object with the current UTC
(A.K.A., GMT or Zulu) time and a UTC time zone.
|
static java.util.GregorianCalendar |
parseISODateTime(java.util.GregorianCalendar gc,
java.lang.String s)
This converts an ISO date time string ([-]YYYY-MM-DDTHH:MM:SS.SSS±ZZ:ZZ) into
a GregorianCalendar object.
|
static java.util.GregorianCalendar |
parseISODateTimeZulu(java.lang.String s)
This converts an ISO (default *ZULU* time zone) date time string ([-]YYYY-MM-DDTHH:MM:SS±ZZ:ZZ) into
a GregorianCalendar object with the Zulu time zone.
|
public static final int YEAR
public static final int MILLISECOND
public static final int SECONDS_PER_MINUTE
public static final int SECONDS_PER_HOUR
public static final int SECONDS_PER_DAY
public static final java.util.TimeZone zuluTimeZone
public static double[] getTimeBaseAndFactor(java.lang.String tsUnits) throws java.lang.Exception
WARNING: don't use the equations above. Use unitsSinceToEpochSeconds or epochSecondsToUnitsSince which correctly handle special cases.
tsUnits
- e.g., "minutes since 1985-01-01".
This may include hours, minutes, seconds, decimal, and Z or timezone offset (default=Zulu).java.lang.Exception
- if trouble (tsUnits is null or invalid)public static double factorToGetSeconds(java.lang.String units) throws java.lang.Exception
units
- java.lang.Exception
- if trouble (e.g., units is null or not an expected value)public static java.util.GregorianCalendar newGCalendarZulu()
public static java.util.GregorianCalendar parseISODateTime(java.util.GregorianCalendar gc, java.lang.String s)
gc
- a GregorianCalendar object. The dateTime will be interpreted
as being in gc's time zone.
Timezone info is relative to the gc's time zone.s
- the dateTimeString in the ISO format (YYYY-MM-DDTHH:MM:SS.SSS±ZZ:ZZ
or -YYYY-MM-DDTHH:MM:SS.SSS±ZZ:ZZ for years B.C.)
For years B.C., use calendar2Year = 1 - BCYear.
Note that BCYears are 1..., so 1 BC is calendar2Year 0 (or 0000),
and 2 BC is calendar2Year -1 (or -0001).
This supports SS.SSS and SS,SSS (which ISO 8601 prefers!).java.lang.RuntimeException
- if trouble (e.g., gc is null or s is null or
not at least #)public static java.util.GregorianCalendar parseISODateTimeZulu(java.lang.String s)
s
- the dateTimeString in the ISO format ([-]YYYY-MM-DDTHH:MM:SS)
This may include hours, minutes, seconds, decimal, and Z or timezone offset (default=Zulu).