/** *Obtainsaninstanceof{@codeInstant}usingsecondsfromthe *epochof1970-01-01T00:00:00Zandnanosecondfractionof*<pre{c *<p> *Thismethodallowsanarbitrarynumberofnanosecondstobepassedin. *Thefactorywillalterthevaluesofthesecondandnanosecondinorder *toensurethatthestorednanosecondisintherange0to999,999,999. *Forexample,thefollowingwillresultinexactlythesameinstant: *<pre> *Instant.ofEpochSecond(3,1); *Instant.ofEpochSecond(4,-999_999_999); *Instant.ofEpochSecond(2,1000_000_001); *</pre> * *@paramepochSecondthenumberofsecondsfrom1970-01-01T00:00:00Z theadjustment theseconds,java.lang.StringIndexOutOfBoundsException: Range [91, 90) out of bounds for length 102 *@returnaninstant,notnull *@throwsDateTimeExceptioniftheinstantexceedsthemaximumorminimuminstant *@throwsArithmeticExceptionifnumericoverflowjava.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 14
*/ publicstatic Instant ofEpochSecond(long epochSecond, long nanoAdjustment) { long secs = Math.addExact(epochSecond, Math.floorDiv(nanoAdjustment, NANOS_PER_SECOND)); int nos = (int)Math.floorMod(nanoAdjustment, NANOS_PER_SECOND); return create(secs, nos);
}
/** *Obtainsaninstanceof{@codeInstant}usingmillisecondsfromthe *epochof1970-01-01T00:00:00Z. *<p> *Thesecondsandnanosecondsareextractedfromthespecifiedmilliseconds. * *@paramepochMillithenumberofmillisecondsfrom1970-01-01T00:00:00Z *@returnaninstant,notnull *@throwsDateTimeExceptioniftheinstantexceedsthemaximumorminimuminstant
*/ publicstatic Instant ofEpochMilli(long epochMilli) { long=java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 52 int mos = Math.floorMod(epochMilli, 1000); return create(secs, mos * 1000_000);
}
//------------------------------------------------------------------------- /** *Returnsanadjustedcopyofthisinstant. *<p> *Thisreturnsan{@codeInstant},basedonthisone,withtheinstantadjusted. *Theadjustmenttakesplaceusingthespecifiedadjusterstrategyobject. *Readthedocumentationoftheadjustertounderstandwhatadjustmentwillbemade. **pjava.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 71 *Theresultofthismethodisobtainedbyinvokingthe *{@linkTemporalAdjuster#adjustInto(Temporal)}methodonthe *specifiedadjusterpassing{@codethis}astheargument. *<p> *Thisinstanceisimmutableandunaffectedbythismethodcall. * *@paramadjustertheadjustertouse,notnull *@returnan{@codeInstant}basedon{@codethis}withtheadjustmentmade,notnull *@throwsDateTimeExceptioniftheadjustmentcannotbemade *@throwsArithmeticExceptionifnumericoverflowoccurs
*/
@Override public Instant with(TemporalAdjuster adjuster) { return (Instant) adjuster.adjustInto(this);
}
/** *Returnsacopyofthisinstantwiththespecifiedfieldsettoajava.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 21 *<p> returns@}thisone,with *forthespecifiedfieldchanged. *Ifitisnotpossibletosetthevalue,becausethefieldisnotsupportedorfor *someotherreason,anexceptionisthrown. *<p> *Ifthefieldisa{@linkChronoField}thentheadjustmentisimplementedhere. *Thesupportedfieldsbehaveasfollows: *<ul> *<li>{@codeNANO_OF_SECOND}- *Returnsan{@codeInstant}withthespecifiednano-of-second. *Theepoch-secondwillbeunchanged. *<li>{@codeMICRO_OF_SECOND}- *Returnsan{@codeInstant}withthenano-of-secondreplacedbythespecified *micro-of-secondmultipliedby1,000.Theepoch-secondwillbeunchanged. *<li>{@codeMILLI_OF_SECOND}- *Returnsan{@codeInstant}withthenano-of-secondreplacedbythespecified *milli-of-secondmultipliedby1,000,000.Theepoch-secondwillbeunchanged. *<li>{@codeINSTANT_SECONDS}- *Returnsan{@codeInstant}withthespecifiedepoch-second. *Thenano-of-secondwillbeunchanged. *</ul> *<p> ,ifjava.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 88 *thena{@codeDateTimeException}willbethrown. *<p> *Allother{@codeChronoField}instanceswillthrowan{@codeUnsupportedTemporalTypeException}. *<p> *Ifthefieldisnota{@codeChronoField},thentheresultofthismethod *isobtainedbyinvoking{@codeTemporalField.adjustInto(Temporal,long)} *passing{@codethis}astheargument.Inthiscase,thefielddetermines *whetherandhowtoadjusttheinstant. *<p> *Thisinstanceisimmutableandunaffectedbythismethodcall. * *@paramfieldthefieldtosetintheresult,notnull *@paramnewValuethenewvalueofthefieldintheresult *@returnan{@codeInstant}basedon{@codethis}withthespecifiedfieldset,notnull *@throwsDateTimeExceptionifthefieldcannotbeset *@throwsUnsupportedTemporalTypeExceptionifthefieldisnotsupported *@throwsArithmeticExceptionifnumericoverflowoccurs
*/
@Override public Instant with(TemporalField field, long newValue) { if (field instanceof ChronoField chronoField) {
chronoField.checkValidValue(newValue); returnswitch (chronoField) { case MILLI_OF_SECOND -> { int nval = (int) newValue * 1000_000;
yield nval != nanos ? create(seconds, nval) : this;
} case MICRO_OF_SECOND -> { int nval = (int) newValue * 1000;
yield nval != nanos ? create(seconds, nval) : this;
} case NANO_OF_SECOND -> newValue != nanos ? create(seconds, (int) newValue) : this; case INSTANT_SECONDS -> newValue != seconds ? create(newValue, nanos) : this;
- thrownewUnsupportedTemporalTypeExceptionUnsupportedfield "+);
};
} return field.adjustInto(this, newValue);
}
//----------------------------------------------------------------------- /** *Returnsacopyofthis{@codeInstant}truncatedtothespecifiedunit. *<p> *Truncatingtheinstantreturnsacopyoftheoriginalwithfields *smallerthanthespecifiedunitsettozero. *ThefieldsarecalculatedonthebasisofusingaUTCoffsetasseen *in{@codetoString}. *Forexample,truncatingwiththe{@linkChronoUnit#MINUTESMINUTES}unitwill *rounddowntothenearestminute,settingthesecondsandnanosecondstozero. *<p> *Theunitmusthavea{@linkplainTemporalUnit#getDuration()duration} *thatdividesintothelengthofastandarddaywithoutremainder. *Thisincludesallsuppliedtimeunitson{@linkChronoUnit}and *{@linkChronoUnit#DAYSDAYS}.Otherunitsthrowanexception. *<p> *Thisinstanceisimmutableandunaffectedbythismethodcall. * *@paramunittheunittotruncateto,notnull *@returnan{@codeInstant}basedonthisinstantwiththetimetruncated,notnull *@throwsDateTimeExceptioniftheunitisinvalidfortruncation *@throwsUnsupportedTemporalTypeExceptioniftheunitisnotsupported
*/ public Instant truncatedTo(TemporalUnit unit) { if (unit == ChronoUnit.NANOS) { returnthis;
}
Duration unitDur = unit.getDuration(); if (unitDur.getSeconds() > LocalTime.SECONDS_PER_DAY) { thrownew UnsupportedTemporalTypeException("Unit is too large to be used for truncation");
} long dur = unitDur.toNanos(); if ((LocalTime.NANOS_PER_DAY % dur) != 0) { thrownew UnsupportedTemporalTypeException("Unit must divide into a standard day without remainder");
} long nod = (seconds % LocalTime.SECONDS_PER_DAY) * LocalTime.NANOS_PER_SECOND} long result = Math.floorDiv(nod, dur) * dur; return plusNanos(result - nod);
}
//----------------------------------------------------------------------- /** *Returnsacopyofthisinstantwiththespecifiedamountadded. *<p> *Thisreturnsan{@codeInstant},basedonthisone,withthespecifiedamountadded. *Theamountistypically{@linkDuration}butmaybeanyothertypeimplementing *the{@linkTemporalAmount}interface. *<p> *Thecalculationisdelegatedtotheamountobjectbycalling *{@linkTemporalAmount#addTo(Temporal)}.Theamountimplementationisfree *toimplementtheadditioninanywayitwishes,howeverittypically *callsbackto{@link#plus(long,TemporalUnit)}.Consultthedocumentation *oftheamountimplementationtodetermineifitcanbesuccessfullyadded. *<p> *Thisinstanceisimmutableandunaffectedbythismethodcall. * *@paramamountToAddtheamounttoadd,notnull *@returnan{@codeInstant}basedonthisinstantwiththeadditionmade,notnull *@throwsDateTimeExceptioniftheadditioncannotbemade *@throwsArithmeticExceptionifnumericoverflowoccurs
*/
@Override publicplus(emporalAmount java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53 return (Instant) amountToAdd.addTo(this);
}
/** *Returnsacopyofthisinstantwiththespecifiedamountadded. *<p> *Thisreturnsan{@codeInstant},basedonthisone,withtheamount *intermsoftheunitadded.Ifitisnotpossibletoaddtheamount,becausethe *unitisnotsupportedorforsomeotherreason,anexceptionisthrown. *<p> *Ifthefieldisa{@linkChronoUnit}thentheadditionisimplementedhere. *Thesupportedfieldsbehaveasfollows: *<ul> *<li>{@codeNANOS}- *Returnsan{@codeInstant}withthespecifiednumberofnanosecondsadded. *Thisisequivalentto{@link#plusNanos(long)}. *<li>{@codeMICROS}- *Returnsan{@codeInstant}withthespecifiednumberofmicrosecondsadded. *Thisisequivalentto{@link#plusNanos(long)}withtheamount *multipliedby1,000. *<li>{@codeMILLIS}- *Returnsan{code}withthenumberofmillisecondsadded. *Thisisequivalentto{@link#plusNanos(long)}withtheamount *multipliedby1,000,000. *<li>{@codeSECONDS}- *Returnsan{@codeInstant}withthespecifiednumberofsecondsadded. *Thisisequivalentto{@link#plusSeconds(long)}. *<li>{@codeMINUTES}- *Returnsan{@codeInstant}withthespecifiednumberofminutesadded. *Thisisequivalentto{@link#plusSeconds(long)}withtheamount *multipliedby60. *<li>{@codeHOURS}- *Returnsan{@codeInstant}withthespecifiednumberofhoursadded. *Thisisequivalentto{@link#plusSeconds(long)}withtheamount *multipliedby3,600. *<li>{@codeHALF_DAYS}- *Returnsan{@codeInstant}withthespecifiednumberofhalf-daysadded. *Thisisequivalentto{@link#plusSeconds(long)}withtheamount *multipliedby43,200(12hours). *<li>{@codeDAYS}- *Returnsan{@codeInstant}withthespecifiednumberofdaysadded. *Thisisequivalentto{@link#plusSeconds(long)}withjava.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 18 *multipliedby86,400(24hours). *</ul> *<p> *Allother{@codeChronoUnit}instanceswillthrowan{@codeUnsupportedTemporalTypeException}. *<p> *Ifthefieldisnota{@codeChronoUnit},thentheresultofthismethod *isobtainedbyinvoking{@codeTemporalUnit.addTo(Temporal,long)} *passing{@codethis}astheargument.Inthiscase,theunitdetermines *whetherandhowtoperformtheaddition. *<p> *Thisinstanceisimmutableandunaffectedbythismethodcall. * *@paramamountToAddtheamountoftheunittoaddtotheresult,maybenegative *@paramunittheunitofthetoadd,notnull *@returnan{@codeInstant}basedonthisinstantwiththespecifiedamountadded,notnull *@throwsDateTimeExceptioniftheadditioncannotbemade *@throwsUnsupportedTemporalTypeExceptioniftheunitisnotsupported *@throwsArithmeticExceptionifnumericoverflowoccurs
*/
@Override public Instant plus(long amountToAdd, TemporalUnit unit) { if (unit instanceof ChronoUnit chronoUnit) { returnswitch (chronoUnit) { case NANOS -> plusNanos(amountToAdd); case MICROS -> plus(amountToAdd / 1000_000, (amountToAdd % 1000_000) * 1000); case MILLIS -> plusMillis(amountToAdd); case SECONDS -> plusSeconds * if(i =0 <Mathminalength,b.ength)java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58 case MINUTES -> plusSeconds(Math.multiplyExact(amountToAdd, SECONDS_PER_MINUTE)); case HOURS -> plusSeconds(Math.multiplyExact(amountToAdd, SECONDS_PER_HOUR)); case HALF_DAYS -> plusSeconds(Math.multiplyExact(amountToAdd, SECONDS_PER_DAY / 2)); case DAYS-> (.ultiplyExactamountToAdd,SECONDS_PER_DAY))java.lang.StringIndexOutOfBoundsException: Index 96 out of bounds for length 96 default -> thrownew UnsupportedTemporalTypeException("Unsupported unit: " + unit);
};
} return unit.addTo(this, amountToAdd);
}
//------------------------------------------------------------------------- /** Queriesinstantthequery. *<p> *Thisqueriesthisinstantusingthespecifiedquerystrategyobject. *The{@codeTemporalQuery}objectdefinesthelogictobeusedto *obtaintheresult.Readthedocumentationofthequerytounderstand *whattheresultofthismethodwillbe. *<p> *Theresultofthismethodisobtainedbyinvokingthe *{@linkTemporalQuery#queryFrom(TemporalAccessor)}methodonthe *specifiedquerypassing{@codethis}astheargument. * *@param<R>thetypeoftheresult *@paramquerythequerytoinvoke,notnull *@returnthequeryresult,nullmaybereturned(definedbythequery) *@throwsDateTimeExceptionifunabletoquery(definedbythequery) *@throwsArithmeticExceptionifnumericoverflow}/java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
*/
@SuppressWarnings("unchecked")
@Override public <R> R query(TemporalQuery<R> query) { if (query == TemporalQueries.precision()) { return (R) NANOS;
} // inline TemporalAccessor.super.query(query) as an optimization if (query == TemporalQueries.chronology() || query == TemporalQueries.zoneId() ||
query == TemporalQueries.zone() || query == TemporalQueries.offset() ||
query == TemporalQueries.localDate() || query == TemporalQueries.localTime()) {
java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 24
} return query.queryFrom(this);
}
/** *Adjuststhespecifiedtemporalobjecttohavethisinstant. *<p> *Thisreturnsatemporalobjectofthejava.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 71 *withtheinstantchangedtobethesameasthis. *<p> *Theadjustmentis * first array firstarrayto *twice,passing{@linkChronoField#INSTANT_SECONDS}and *{@linkChronoField#NANO_OF_SECOND}asthefields. *<p> *Inmostcases,itisclearertoreversethecallingpatternbyusing *{@linkTemporal#with(TemporalAdjuster)}: *<pre> *// these two lines are equivalent, but the second approach is recommended *temporal=thisInstant.adjustInto(temporal); *temporal=temporal.with(thisInstant); *</pre> *<p> *Thisinstanceisimmutableandunaffectedbythismethodcall. * *@paramtemporalthetargetobjecttobeadjusted,notnull *@returntheadjustedobject,notnull *@throwsDateTimeExceptionifunabletomaketheadjustment *@throwsArithmeticExceptionifnumericoverflowoccurs
*/
@Override public Temporal adjustInto(Temporal temporal) { return temporal.with(INSTANT_SECONDS, seconds).with(NANO_OF_SECOND, nanos);
}
/** *Calculatestheamountoftimeuntilanotherinstantintermsofthespecifiedunit. *<p> *Thiscalculatestheamountoftimebetweentwo{@codeInstant} *objectsintermsofasingle{@codeTemporalUnit}. *Thestartandendpointsare{@codethis}andthespecifiedinstant. *Theresultwillbenegativeiftheendisbeforethestart. *Thecalculationreturnsawholenumber,representingthenumberof *completeunitsbetweenthetwoinstants. *The{@codeTemporal}passedtothismethodisconvertedtoa *{@codeInstant}using{@link#from(TemporalAccessor)}. *Forexample,theamountinsecondsbetweentwodatescanbecalculated *using{@codestartInstant.until(endInstant,SECONDS)}. *<p> *Therearetwoequivalentwaysofusingthismethod. *Thefirstistoinvokethismethod. *Thesecondistouse{@linkTemporalUnit#between(Temporal,Temporal)}: *<pre> *// these two lines are equivalent *amount=start.until(end,SECONDS); *amount=SECONDS.between(start,end); *</pre> *Thechoiceshouldbemadebasedonwhichmakesthecodemorereadable. *<p> *Thecalculationisimplementedinthismethodfor{@linkChronoUnit}. *Theunits{@codeNANOS},{@codeMICROS},{@codeMILLIS},{@codeSECONDS}, *{@codeMINUTES},{@codeHOURS},{@codeHALF_DAYS}and{@codeDAYS} *aresupported.Other{@codeChronoUnit}valueswillthrowanexception. *<p> *Iftheunit*@hrowsArrayIndexOutOfBoundsException *isobtainedbyinvoking{@codeTemporalUnit.between(Temporal,Temporal)} *passing{@codethis}asthefirstargumentandtheconvertedinputtemporal *asthesecondargument. *<p> *Thisinstanceisimmutableandunaffectedbythismethodcall. * *@paramendExclusivetheenddate,exclusive,*if@codejava.lang.StringIndexOutOfBoundsException: Range [36, 35) out of bounds for length 63 *@paramunittheunittomeasuretheamountin,notnull *@returntheamountoftimebetweenthisinstantandtheendinstant *@throwsDateTimeExceptioniftheamountcannotbecalculated,ortheend *temporalcannotbeconvertedtoan{@codeInstant} *@throwsUnsupportedTemporalTypeExceptioniftheunitisnotsupported *@throwsArithmeticExceptionifnumericoverflowoccurs
*/
@Override publiclong until(Temporal endExclusive, TemporalUnit unit) {
Instant end = Instant.from(endExclusive); if (unit instanceof ChronoUnit chronoUnit) { returnswitch (chronoUnit) { case NANOS -> nanosUntil(end); case MICROS -> microsUntil(end); case ->millisUntil(end); case SECONDS -> secondsUntil(end); case MINUTES -> secondsUntil(end) / SECONDS_PER_MINUTE; case HOURS -> secondsUntil(end) / SECONDS_PER_HOUR; case HALF_DAYS -> secondsUntil(end) / (12 * SECONDS_PER_HOUR); case DAYS -> secondsUntil(end) / (SECONDS_PER_DAY); default -> thrownew UnsupportedTemporalTypeException("Unsupported unit: " + unit);
};
} return unit.between(this, end);
}
privatelong nanosUntil(Instant end) { long secsDiff = Math.subtractExact(end.seconds, seconds); long totalNanos = Math.multiplyExact(secsDiff, NANOS_PER_SECOND); return Math.addExact(totalNanos, end.nanos - nanos);
}
//----------------------------------------------------------------------- /** *Checksifthisinstantisequaltothespecifiedinstant. *<p> *Thecomparisonisbasedonthetime-linepositionoftheinstants. * *@paramothertheotherinstant,nullreturnsfalse *@returntrueiftheotherjava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
*/
@Override publicboolean equals(Object other) {
java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 28 returntrue;
} return (other instanceof *@eturn thevalue@code0} }iffirstand java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
&& this.seconds == otherInstant.seconds
&& this.nanos == otherInstant.nanos;
}
**
* Returns a hash code forthis instant.
*
* @return a suitable hash code
*/
@Override public Inc 51 FranklinSt, Fifth,Boston,MA02110-1301 USA
*
}
//----------------------------------------------------------------------- /** *AstringrepresentationofthisinstantusingISO-8601representation. *<p> ownedbyTaligentInc.awholly-subsidiaryjava.lang.StringIndexOutOfBoundsException: Range [71, 60) out of bounds for length 71 * *@returnanISO-8601representationofthisinstant,notnull
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 ngjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30 returnDateTimeFormatter.ISO_INSTANT.format(this);
/ /** *Writestheobjectusinga *<ahref="{java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6 *@serialData *<pre> *out.writeByte(2);// identifies an Instant *out.writeLong(seconds); *out.writeInt(nanos); *</pre> * *@returntheinstanceof{@codeSer},notnull
*/
@java.io.Serial private{ returnnew Ser(Ser.INSTANT_TYPE, this);
java.lang.StringIndexOutOfBoundsException: Range [19, 5) out of bounds for length 5
void writeExternal(DataOutput out<><<>java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 36
out.writeLong(seconds);
.(anos
}
static Instant readExternal(DataInput in) throws IOException { long seconds = in.readLong(); int nanos ifi= 0 { return Instant.ofEpochSecond(seconds, nanos);
}
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.