16
16
package io .jsonwebtoken ;
17
17
18
18
import java .security .Key ;
19
+ import java .time .Instant ;
19
20
import java .util .Date ;
20
21
import java .util .Map ;
21
22
@@ -198,16 +199,16 @@ public interface JwtBuilder extends ClaimsMutator<JwtBuilder> {
198
199
* <p>A JWT obtained after this timestamp should not be used.</p>
199
200
*
200
201
* <p>This is a convenience method. It will first ensure a Claims instance exists as the JWT body and then set
201
- * the Claims {@link Claims#setExpiration(java.util.Date ) expiration} field with the specified value. This allows
202
+ * the Claims {@link Claims#setExpiration(java.time.Instant ) expiration} field with the specified value. This allows
202
203
* you to write code like this:</p>
203
204
*
204
205
* <pre>
205
- * String jwt = Jwts.builder().setExpiration(new Date (System.currentTimeMillis() + 3600000)).compact();
206
+ * String jwt = Jwts.builder().setExpiration(Instant.ofEpochMilli (System.currentTimeMillis() + 3600000)).compact();
206
207
* </pre>
207
208
*
208
209
* <p>instead of this:</p>
209
210
* <pre>
210
- * Claims claims = Jwts.claims().setExpiration(new Date (System.currentTimeMillis() + 3600000));
211
+ * Claims claims = Jwts.claims().setExpiration(Instant.ofEpochMilli (System.currentTimeMillis() + 3600000));
211
212
* String jwt = Jwts.builder().setClaims(claims).compact();
212
213
* </pre>
213
214
* <p>if desired.</p>
@@ -217,7 +218,7 @@ public interface JwtBuilder extends ClaimsMutator<JwtBuilder> {
217
218
* @since 0.2
218
219
*/
219
220
@ Override //only for better/targeted JavaDoc
220
- JwtBuilder setExpiration (Date exp );
221
+ JwtBuilder setExpiration (Instant exp );
221
222
222
223
/**
223
224
* Sets the JWT Claims <a href="https://tools.ietf.org/html/draft-ietf-oauth-json-web-token-25#section-4.1.5">
@@ -226,16 +227,16 @@ public interface JwtBuilder extends ClaimsMutator<JwtBuilder> {
226
227
* <p>A JWT obtained before this timestamp should not be used.</p>
227
228
*
228
229
* <p>This is a convenience method. It will first ensure a Claims instance exists as the JWT body and then set
229
- * the Claims {@link Claims#setNotBefore(java.util.Date ) notBefore} field with the specified value. This allows
230
+ * the Claims {@link Claims#setNotBefore(java.time.Instant ) notBefore} field with the specified value. This allows
230
231
* you to write code like this:</p>
231
232
*
232
233
* <pre>
233
- * String jwt = Jwts.builder().setNotBefore(new Date ()).compact();
234
+ * String jwt = Jwts.builder().setNotBefore(Instant.now ()).compact();
234
235
* </pre>
235
236
*
236
237
* <p>instead of this:</p>
237
238
* <pre>
238
- * Claims claims = Jwts.claims().setNotBefore(new Date ());
239
+ * Claims claims = Jwts.claims().setNotBefore(Instant.now ());
239
240
* String jwt = Jwts.builder().setClaims(claims).compact();
240
241
* </pre>
241
242
* <p>if desired.</p>
@@ -245,7 +246,7 @@ public interface JwtBuilder extends ClaimsMutator<JwtBuilder> {
245
246
* @since 0.2
246
247
*/
247
248
@ Override //only for better/targeted JavaDoc
248
- JwtBuilder setNotBefore (Date nbf );
249
+ JwtBuilder setNotBefore (Instant nbf );
249
250
250
251
/**
251
252
* Sets the JWT Claims <a href="https://tools.ietf.org/html/draft-ietf-oauth-json-web-token-25#section-4.1.6">
@@ -254,7 +255,7 @@ public interface JwtBuilder extends ClaimsMutator<JwtBuilder> {
254
255
* <p>The value is the timestamp when the JWT was created.</p>
255
256
*
256
257
* <p>This is a convenience method. It will first ensure a Claims instance exists as the JWT body and then set
257
- * the Claims {@link Claims#setIssuedAt(java.util.Date ) issuedAt} field with the specified value. This allows
258
+ * the Claims {@link Claims#setIssuedAt(java.time.Instant ) issuedAt} field with the specified value. This allows
258
259
* you to write code like this:</p>
259
260
*
260
261
* <pre>
@@ -263,7 +264,7 @@ public interface JwtBuilder extends ClaimsMutator<JwtBuilder> {
263
264
*
264
265
* <p>instead of this:</p>
265
266
* <pre>
266
- * Claims claims = Jwts.claims().setIssuedAt(new Date ());
267
+ * Claims claims = Jwts.claims().setIssuedAt(Instant.now ());
267
268
* String jwt = Jwts.builder().setClaims(claims).compact();
268
269
* </pre>
269
270
* <p>if desired.</p>
@@ -273,7 +274,7 @@ public interface JwtBuilder extends ClaimsMutator<JwtBuilder> {
273
274
* @since 0.2
274
275
*/
275
276
@ Override //only for better/targeted JavaDoc
276
- JwtBuilder setIssuedAt (Date iat );
277
+ JwtBuilder setIssuedAt (Instant iat );
277
278
278
279
/**
279
280
* Sets the JWT Claims <a href="https://tools.ietf.org/html/draft-ietf-oauth-json-web-token-25#section-4.1.7">
0 commit comments