// Initialized just before the value is used. See parse(). privatestaticint defaultCenturyStart;
/* use serialVersionUID from modified java.util.Date for *interoperabilitywithJDK1.1.TheDatewasmodifiedtowrite *andreadonlytheUTCtime.
*/
@java.io.Serial privatestaticfinallong serialVersionUID = 7523967970034938905L;
/** *Returnacopyofthisobject.
*/ public Object clone() {
Date d = null; try {
d = (Date)super.clone(); if (cdate != null) {
d.cdate = (BaseCalendar.Date) cdate.clone();
}
} catch (CloneNotSupportedException e) {} // Won't happen return d;
}
/** *Determinesthedateandtimebasedonthearguments.The *argumentsareinterpretedasayear,month,dayofthemonth, *houroftheday,minutewithinthehour,andsecondwithinthe *minute,exactlyasforthe{@codeDate}constructorwithsix *arguments,exceptthattheargumentsareinterpretedrelative *toUTCratherthantothelocaltimezone.Thetimeindicatedis *returnedrepresentedasthedistance,measuredinmilliseconds, *ofthattimefromtheepoch(00:00:00GMTonJanuary1,1970). * *@paramyeartheyearminus1900. *@parammonththemonthbetween0-11. *@paramdatethedayofthemonthbetween1-31. *@paramhrsthehoursbetween0-23. *@parammintheminutesbetween0-59. *@paramsecthesecondsbetween0-59. *@returnthenumberofmillisecondssinceJanuary1,1970,00:00:00GMTfor *thedateandtimespecifiedbythearguments. *@seejava.util.Calendar *@deprecatedAsofJDKversion1.1, *replacedby{@codeCalendar.set(year+1900,month,date,hrs,min,sec)} *or{@codeGregorianCalendar(year+1900,month,date,hrs,min,sec)},usingaUTC *{@codeTimeZone},followedby{@codeCalendar.getTime().getTime()}.
*/
@Deprecated publicstaticlong UTC(int year, int month, int date, int hrs, int min, int sec) { int y = year + 1900; // month is 0-based. So we have to normalize month to support Long.MAX_VALUE. if (month >= 12) {
y += month / 12;
month %= 12;
} elseif (month < 0) {
y += CalendarUtils.floorDivide(month, 12);
month = CalendarUtils.mod(month, 12);
} int m = month + 1;
BaseCalendar cal = getCalendarSystem(y);
BaseCalendar.Date udate = (BaseCalendar.Date) cal.newCalendarDate(null);
udate.setNormalizedDate(y, m, date).setTimeOfDay(hrs, min, sec, 0);
// Use a Date instance to perform normalization. Its fastTime // is the UTC value after the normalization.
Date d = new Date(0);
d.normalize(udate); return d.fastTime;
}
/** *Attemptstointerpretthestring{@codes}asarepresentation *ofadateandtime.Iftheattemptissuccessful,thetime *indicatedisreturnedrepresentedasthedistance,measuredin *milliseconds,ofthattimefromtheepoch(00:00:00GMTon *January1,1970).Iftheattemptfails,an *{@codeIllegalArgumentException}isthrown. *<p> *Itacceptsmanysyntaxes;inparticular,itrecognizestheIETF *standarddatesyntax:"Sat,12Aug199513:30:00GMT".Italso *understandsthecontinentalU.S.time-zoneabbreviations,butfor *generaluse,atime-zoneoffsetshouldbeused:"Sat,12Aug1995 *13:30:00GMT+0430"(4hours,30minuteswestoftheGreenwich *meridian).Ifnotimezoneisspecified,thelocaltimezoneis *assumed.GMTandUTCareconsideredequivalent. *<p> *Thestring{@codes}isprocessedfromlefttoright,lookingfor *dataofinterest.Anymaterialin{@codes}thatiswithinthe *ASCIIparenthesischaracters{@code(}and{@code)}isignored. *Parenthesesmaybenested.Otherwise,theonlycharacterspermitted *within{@codes}aretheseASCIIcharacters: *<blockquote><pre> *abcdefghijklmnopqrstuvwxyz *ABCDEFGHIJKLMNOPQRSTUVWXYZ *0123456789,+-:/</pre></blockquote> *andwhitespacecharacters.<p> *Aconsecutivesequenceofdecimaldigitsistreatedasadecimal *number:<ul> *<li>Ifanumberisprecededby{@code+}or{@code-}andayear *hasalreadybeenrecognized,thenthenumberisatime-zone *offset.Ifthenumberislessthan24,itisanoffsetmeasured *inhours.Otherwise,itisregardedasanoffsetinminutes, *expressedin24-hourtimeformatwithoutpunctuation.A *preceding{@code-}meansawestwardoffset.Timezoneoffsets *arealwaysrelativetoUTC(Greenwich).Thus,forexample, *{@code-5}occurringinthestringwouldmean"fivehourswest *ofGreenwich"and{@code+0430}wouldmean"fourhoursand *thirtyminuteseastofGreenwich."Itispermittedforthe *stringtospecify{@codeGMT},{@codeUT},or{@codeUTC} *redundantly-forexample,{@codeGMT-5}or{@codeutc+0430}. *<li>Thenumberisregardedasayearnumberifoneofthe *followingconditionsistrue: *<ul> *<li>Thenumberisequaltoorgreaterthan70andfollowedbya *space,comma,slash,orendofstring *<li>Thenumberislessthan70,andbothamonthandadayof *themonthhavealreadybeenrecognized</li> *</ul> *Iftherecognizedyearnumberislessthan100,itis *interpretedasanabbreviatedyearrelativetoacenturyof *whichdatesarewithin80yearsbeforeand19yearsafter *thetimewhentheDateclassisinitialized. *Afteradjustingtheyearnumber,1900issubtractedfrom *it.Forexample,ifthecurrentyearis1999thenyearsin *therange19to99areassumedtomean1919to1999,while *yearsfrom0to18areassumedtomean2000to2018.Note *thatthisisslightlydifferentfromtheinterpretationof *yearslessthan100thatisusedin{@linkjava.text.SimpleDateFormat}. *<li>Ifthenumberisfollowedbyacolon,itisregardedasanhour, *unlessanhourhasalreadybeenrecognized,inwhichcaseitis *regardedasaminute. *<li>Ifthenumberisfollowedbyaslash,itisregardedasamonth *(itisdecreasedby1toproduceanumberintherange{@code0} *to{@code11}),unlessamonthhasalreadybeenrecognized,in *whichcaseitisregardedasadayofthemonth. *<li>Ifthenumberisfollowedbywhitespace,acomma,ahyphen,or *endofstring,thenifanhourhasbeenrecognizedbutnota *minute,itisregardedasaminute;otherwise,ifaminutehas *beenrecognizedbutnotasecond,itisregardedasasecond; *otherwise,itisregardedasadayofthemonth.</ul><p> *Aconsecutivesequenceoflettersisregardedasawordandtreated *asfollows:<ul> *<li>Awordthatmatches{@codeAM},ignoringcase,isignored(but *theparsefailsifanhourhasnotbeenrecognizedorisless *than{@code1}orgreaterthan{@code12}). *<li>Awordthatmatches{@codePM},ignoringcase,adds{@code12} *tothehour(buttheparsefailsifanhourhasnotbeen *recognizedorislessthan{@code1}orgreaterthan{@code12}). *<li>Anywordthatmatchesanyprefixof{@codeSUNDAY,MONDAY,TUESDAY, *WEDNESDAY,THURSDAY,FRIDAY},or{@codeSATURDAY},ignoring *case,isignored.Forexample,{@codesat,Friday,TUE},and *{@codeThurs}areignored. *<li>Otherwise,anywordthatmatchesanyprefixof{@codeJANUARY, *FEBRUARY,MARCH,APRIL,MAY,JUNE,JULY,AUGUST,SEPTEMBER, *OCTOBER,NOVEMBER},or{@codeDECEMBER},ignoringcase,and *consideringthemintheordergivenhere,isrecognizedas *specifyingamonthandisconvertedtoanumber({@code0}to *{@code11}).Forexample,{@codeaug,Sept,april},and *{@codeNOV}arerecognizedasmonths.Sois{@codeMa},which *isrecognizedas{@codeMARCH},not{@codeMAY}. *<li>Anywordthatmatches{@codeGMT,UT},or{@codeUTC},ignoring *case,istreatedasreferringtoUTC. *<li>Anywordthatmatches{@codeEST,CST,MST},or{@codePST}, *ignoringcase,isrecognizedasreferringtothetimezonein *NorthAmericathatisfive,six,seven,oreighthourswestof *Greenwich,respectively.Anywordthatmatches{@codeEDT,CDT, *MDT},or{@codePDT},ignoringcase,isrecognizedas *referringtothesametimezone,respectively,duringdaylight *savingtime.</ul><p> *Oncetheentirestringshasbeenscanned,itisconvertedtoatime *resultinoneoftwoways.Ifatimezoneortime-zoneoffsethasbeen *recognized,thentheyear,month,dayofmonth,hour,minute,and *secondareinterpretedinUTCandthenthetime-zoneoffsetis *applied.Otherwise,theyear,month,dayofmonth,hour,minute,and *secondareinterpretedinthelocaltimezone. * *@paramsastringtobeparsedasadate. *@returnthenumberofmillisecondssinceJanuary1,1970,00:00:00GMT *representedbythestringargument. *@seejava.text.DateFormat *@deprecatedAsofJDKversion1.1, *replacedby{@codeDateFormat.parse(Strings)}.
*/
@Deprecated publicstaticlong parse(String s) { int year = Integer.MIN_VALUE; int mon = -1; int mday = -1; int hour = -1; int min = -1; int sec = -1; int millis = -1; int c = -1; int i = 0; int n = -1; int wst = -1; int tzoffset = -1; int prevc = 0;
syntax:
{ if (s == null) break syntax; int limit = s.length(); while (i < limit) {
c = s.charAt(i);
i++; if (c <= ' ' || c == ',') continue; if (c == '(') { // skip comments int depth = 1; while (i < limit) {
c = s.charAt(i);
i++; if (c == '(') depth++; elseif (c == ')') if (--depth <= 0) break;
} continue;
} if ('0' <= c && c <= '9') {
n = c - '0'; while (i < limit && '0' <= (c = s.charAt(i)) && c <= '9') {
n = n * 10 + c - '0';
i++;
} if (prevc == '+' || prevc == '-' && year != Integer.MIN_VALUE) { // timezone offset if (n < 24)
n = n * 60; // EG. "GMT-3" else
n = n % 100 + n / 100 * 60; // eg "GMT-0430" if (prevc == '+') // plus means east of GMT
n = -n; if (tzoffset != 0 && tzoffset != -1) break syntax;
tzoffset = n;
} elseif (n >= 70) if (year != Integer.MIN_VALUE) break syntax; elseif (c <= ' ' || c == ',' || c == '/' || i >= limit) // year = n < 1900 ? n : n - 1900;
year = n; else break syntax; elseif (c == ':') if (hour < 0)
hour = (byte) n; elseif (min < 0)
min = (byte) n; else break syntax; elseif (c == '/') if (mon < 0)
mon = (byte) (n - 1); elseif (mday < 0)
mday = (byte) n; else break syntax; elseif (i < limit && c != ',' && c > ' ' && c != '-') break syntax; elseif (hour >= 0 && min < 0)
min = (byte) n; elseif (min >= 0 && sec < 0)
sec = (byte) n; elseif (mday < 0)
mday = (byte) n; // Handle two-digit years < 70 (70-99 handled above). elseif (year == Integer.MIN_VALUE && mon >= 0 && mday >= 0)
year = n; else break syntax;
prevc = 0;
} elseif (c == '/' || c == ':' || c == '+' || c == '-')
prevc = c; else { int st = i - 1; while (i < limit) {
c = s.charAt(i); if (!('A' <= c && c <= 'Z' || 'a' <= c && c <= 'z')) break;
i++;
} if (i <= st + 1) break syntax; int k; for (k = wtb.length; --k >= 0;) if (wtb[k].regionMatches(true, 0, s, st, i - st)) { int action = ttb[k]; if (action != 0) { if (action == 1) { // pm if (hour > 12 || hour < 1) break syntax; elseif (hour < 12)
hour += 12;
} elseif (action == 14) { // am if (hour > 12 || hour < 1) break syntax; elseif (hour == 12)
hour = 0;
} elseif (action <= 13) { // month! if (mon < 0)
mon = (byte) (action - 2); else break syntax;
} else {
tzoffset = action - 10000;
}
} break;
} if (k < 0) break syntax;
prevc = 0;
}
} if (year == Integer.MIN_VALUE || mon < 0 || mday < 0) break syntax; // Parse 2-digit years within the correct default century. if (year < 100) { synchronized (Date.class) { if (defaultCenturyStart == 0) {
defaultCenturyStart = gcal.getCalendarDate().getYear() - 80;
}
}
year += (defaultCenturyStart / 100) * 100; if (year < defaultCenturyStart) year += 100;
} if (sec < 0)
sec = 0; if (min < 0)
min = 0; if (hour < 0)
hour = 0;
BaseCalendar cal = getCalendarSystem(year); if (tzoffset == -1) { // no time zone specified, have to use local
BaseCalendar.Date ldate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.getDefaultRef());
ldate.setDate(year, mon + 1, mday);
ldate.setTimeOfDay(hour, min, sec, 0); return cal.getTime(ldate);
}
BaseCalendar.Date udate = (BaseCalendar.Date) cal.newCalendarDate(null); // no time zone
udate.setDate(year, mon + 1, mday);
udate.setTimeOfDay(hour, min, sec, 0); return cal.getTime(udate) + tzoffset * (60 * 1000);
} // syntax error thrownew IllegalArgumentException();
} privatestaticfinal String wtb[] = { "am", "pm", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday", "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december", "gmt", "ut", "utc", "est", "edt", "cst", "cdt", "mst", "mdt", "pst", "pdt"
}; privatestaticfinalint ttb[] = { 14, 1, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 10000 + 0, 10000 + 0, 10000 + 0, // GMT/UT/UTC 10000 + 5 * 60, 10000 + 4 * 60, // EST/EDT 10000 + 6 * 60, 10000 + 5 * 60, // CST/CDT 10000 + 7 * 60, 10000 + 6 * 60, // MST/MDT 10000 + 8 * 60, 10000 + 7 * 60// PST/PDT
};
// Normalize cdate with the TimeZone in cdate first. This is // required for the compatible behavior. if (!cdate.isNormalized()) {
cdate = normalize(cdate);
}
// If the default TimeZone has changed, then recalculate the // fields with the new TimeZone.
TimeZone tz = TimeZone.getDefaultRef(); if (tz != cdate.getZone()) {
cdate.setZone(tz);
CalendarSystem cal = getCalendarSystem(cdate);
cal.getCalendarDate(fastTime, cdate);
} return cdate;
}
// fastTime and the returned data are in sync upon return. privatefinal BaseCalendar.Date normalize(BaseCalendar.Date date) { int y = date.getNormalizedYear(); int m = date.getMonth(); int d = date.getDayOfMonth(); int hh = date.getHours(); int mm = date.getMinutes(); int ss = date.getSeconds(); int ms = date.getMillis();
TimeZone tz = date.getZone();
// If the specified year can't be handled using a long value // in milliseconds, GregorianCalendar is used for full // compatibility with underflow and overflow. This is required // by some JCK tests. The limits are based max year values - // years that can be represented by max values of d, hh, mm, // ss and ms. Also, let GregorianCalendar handle the default // cutover year so that we don't need to worry about the // transition here. if (y == 1582 || y > 280000000 || y < -280000000) { if (tz == null) {
tz = TimeZone.getTimeZone("GMT");
}
GregorianCalendar gc = new GregorianCalendar(tz);
gc.clear();
gc.set(GregorianCalendar.MILLISECOND, ms);
gc.set(y, m-1, d, hh, mm, ss);
fastTime = gc.getTimeInMillis();
BaseCalendar cal = getCalendarSystem(fastTime);
date = (BaseCalendar.Date) cal.getCalendarDate(fastTime, tz); return date;
}
BaseCalendar cal = getCalendarSystem(y); if (cal != getCalendarSystem(date)) {
date = (BaseCalendar.Date) cal.newCalendarDate(tz);
date.setNormalizedDate(y, m, d).setTimeOfDay(hh, mm, ss, ms);
} // Perform the GregorianCalendar-style normalization.
fastTime = cal.getTime(date);
// In case the normalized date requires the other calendar // system, we need to recalculate it using the other one.
BaseCalendar ncal = getCalendarSystem(fastTime); if (ncal != cal) {
date = (BaseCalendar.Date) ncal.newCalendarDate(tz);
date.setNormalizedDate(y, m, d).setTimeOfDay(hh, mm, ss, ms);
fastTime = ncal.getTime(date);
} return date;
}
privatestaticfinal BaseCalendar getCalendarSystem(long utc) { // Quickly check if the time stamp given by `utc' is the Epoch // or later. If it's before 1970, we convert the cutover to // local time to compare. if (utc >= 0
|| utc >= GregorianCalendar.DEFAULT_GREGORIAN_CUTOVER
- TimeZone.getDefaultRef().getOffset(utc)) { return gcal;
} return getJulianCalendar();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.