List of usage examples for java.util Date from
public static Date from(Instant instant)
From source file:Main.java
/** Convert a calendar date into a string as specified by http://tools.ietf.org/html/rfc822#section-5.1 * @param date the calendar instance to convert to a string * @param locale the locale to use when outputting strings such as a day of the week, or month of the year. * @return a string in the format: "day_abbreviation, day_of_month month_abbreviation year hour:minute:second GMT" *///from w w w . ja va 2 s. co m // package-private - unused static final String convertDateToStringRfc822(Calendar date, Locale locale) { Date a = Date.from(Instant.now()); a.toString(); int day = date.get(Calendar.DAY_OF_MONTH); int hour = date.get(Calendar.HOUR_OF_DAY); int minute = date.get(Calendar.MINUTE); int second = date.get(Calendar.SECOND); String str = date.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, locale) + ", " + (day < 10 ? "0" + day : day) + " " + date.getDisplayName(Calendar.MONTH, Calendar.SHORT, locale) + " " + date.get(Calendar.YEAR) + " " + (hour < 10 ? "0" + hour : hour) + ":" + (minute < 10 ? "0" + minute : minute) + ":" + (second < 10 ? "0" + second : second) + " GMT"; return str; }
From source file:org.codice.alliance.transformer.nitf.NitfAttributeConverters.java
@Nullable public static Date nitfDate(@Nullable DateTime nitfDateTime) { if (nitfDateTime == null || nitfDateTime.getZonedDateTime() == null) { return null; }/* www . j av a 2 s . c o m*/ ZonedDateTime zonedDateTime = nitfDateTime.getZonedDateTime(); Instant instant = zonedDateTime.toInstant(); return Date.from(instant); }
From source file:org.openhab.binding.gardena.internal.util.DateUtils.java
/** * Converts a string to a Date, trying different date formats used by Gardena. *//*w w w.j a v a2 s. co m*/ public static Date parseToDate(String text) { if (StringUtils.isNotBlank(text)) { Date parsedDate = null; for (String dateFormat : dateFormats) { try { parsedDate = new SimpleDateFormat(dateFormat).parse(text); ZonedDateTime gmt = ZonedDateTime.ofInstant(parsedDate.toInstant(), ZoneOffset.UTC); LocalDateTime here = gmt.withZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime(); parsedDate = Date.from(here.toInstant(ZoneOffset.UTC)); break; } catch (ParseException ex) { } } if (parsedDate == null) { LOGGER.error("Can't parse date {}", text); } return parsedDate; } else { return null; } }
From source file:fr.ffremont.caching.ExpireCache.java
@GET @Path("use1month") public Response use120sec() { Date expires = Date.from(Instant.now().plus(30, ChronoUnit.DAYS)); return Response.ok("ok").expires(expires).build(); }
From source file:com.todo.backend.security.JWTUtils.java
public static String createToken(Long userId, UserRole userRole, String secretKey) { final ZonedDateTime validity = ZonedDateTime.now(ZoneId.of("UTC")).plusSeconds(VALIDITY); return Jwts.builder().setSubject(userId.toString()).claim(AUTHORITIES_KEY, userRole.name()) .signWith(SignatureAlgorithm.HS512, secretKey).setExpiration(Date.from(validity.toInstant())) .compact();/*from ww w .ja v a 2s . c o m*/ }
From source file:fr.ffremont.caching.ExpireCache.java
@GET @Path("mix10sec") public Response mix10sec() { Date expires = Date.from(Instant.now().plus(10, ChronoUnit.SECONDS)); CacheControl cache = new CacheControl(); cache.setMaxAge(60);// w ww . java 2 s. co m LOG.info("Retour du contenu"); return Response.ok("En cache pendant 10sec").cacheControl(cache).expires(expires).build(); }
From source file:com.ewerk.prototype.persistence.converters.LocalDateToDateConverter.java
@Override public Date convert(LocalDate localDate) { if (localDate == null) { return null; }//from w w w .j av a 2 s . c o m return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); }
From source file:com.codepalousa.restlet.raml.DateTimeDeserializeConverter.java
@Override public Date convert(String value) { return Date.from(formatter.parse(value, OffsetDateTime::from).toInstant()); }
From source file:eu.off.db.entity.MemberTest.java
@Test public void BuildMinimalMember() { LocalDateTime dateTime = LocalDateTime.of(1978, Month.APRIL, 4, 0, 0); Date birthday = Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant()); Member aMember = new MemberBuilder(LAST_NAME, FIRST_NAME, STREET, ZIP_CODE, PLACE, COUNTRY, birthday, GENDER, NATIONALITY).build(); assertThat(aMember.getLastName().equals(LAST_NAME)); assertThat(aMember.getFirstName().equals(FIRST_NAME)); assertThat(aMember.getAdress().equals(STREET)); assertThat(aMember.getZipCode().equals(ZIP_CODE)); assertThat(aMember.getPlace().equals(PLACE)); assertThat(aMember.getCountry().equals(COUNTRY)); assertThat(aMember.getBirthday().equals(birthday)); assertThat(aMember.getGender().equals(GENDER)); assertThat(aMember.getNationality().equals(NATIONALITY)); }
From source file:com.ikanow.aleph2.core.shared.utils.TimeSliceDirUtils.java
/** Given a pair of (optional) human readable strings (which are assumed to refer to the past) * returns a pair of optional dates/*from w w w . j a v a 2 s .co m*/ * @param input_config * @return */ public static Tuple2<Optional<Date>, Optional<Date>> getQueryTimeRange( final AnalyticThreadJobInputConfigBean input_config, final Date now) { Function<Optional<String>, Optional<Date>> parseDate = maybe_date -> maybe_date .map(datestr -> TimeUtils.getSchedule(datestr, Optional.of(now))).filter(res -> res.isSuccess()) .map(res -> res.success()) // OK so this wants to be backwards in time always... .map(date -> { if (date.getTime() > now.getTime()) { final long diff = date.getTime() - now.getTime(); return Date.from(now.toInstant().minusMillis(diff)); } else return date; }); final Optional<Date> tmin = parseDate.apply(Optional.ofNullable(input_config.time_min())); final Optional<Date> tmax = parseDate.apply(Optional.ofNullable(input_config.time_max())); return Tuples._2T(tmin, tmax); }