List of usage examples for java.time ZoneOffset UTC
ZoneOffset UTC
To view the source code for java.time ZoneOffset UTC.
Click Source Link
From source file:org.ligoj.app.plugin.prov.aws.auth.AWS4SignerForAuthorizationHeaderTest.java
/** * Test method for/*from w ww .j av a 2 s.c om*/ * {@link org.ligoj.app.plugin.prov.aws.auth.AWS4SignerForAuthorizationHeader#computeSignature(org.ligoj.app.plugin.prov.aws.auth.AWS4SignatureQuery)}. */ @Test public void testComputeSignature() { ReflectionTestUtils.setField(signer, "clock", Clock.fixed( LocalDateTime.of(2017, 5, 29, 22, 15).toInstant(ZoneOffset.UTC), ZoneOffset.UTC.normalized())); final AWS4SignatureQuery signatureQuery = AWS4SignatureQuery.builder().accessKey("awsAccessKey") .secretKey("awsSecretKey").region("eu-west-1").method("GET").service("s3").path("path").build(); Assertions.assertEquals( "AWS4-HMAC-SHA256 Credential=awsAccessKey/20170529/eu-west-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=6a48aa41b25ea6d1b0e636c78ea971de060256ea2a2b2e6b103d6fbf14c7d21a", signer.computeSignature(signatureQuery)); }
From source file:org.nodatime.tzvalidate.Java8Dump.java
@Override public ZoneTransitions getTransitions(String id, int fromYear, int toYear) { ZoneId zone = ZoneId.of(id); ZoneRules rules = zone.getRules(); DateTimeFormatter nameFormat = DateTimeFormatter.ofPattern("zzz", Locale.US); ZoneTransitions transitions = new ZoneTransitions(id); Instant start = ZonedDateTime.of(fromYear, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).toInstant(); transitions.addTransition(null, rules.getOffset(start).getTotalSeconds() * 1000, rules.isDaylightSavings(start), nameFormat.format(start.atZone(zone))); Instant end = ZonedDateTime.of(toYear, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).toInstant(); ZoneOffsetTransition transition = rules.nextTransition(start.minusNanos(1)); while (transition != null && transition.getInstant().isBefore(end)) { Instant instant = transition.getInstant(); transitions.addTransition(new Date(instant.toEpochMilli()), rules.getOffset(instant).getTotalSeconds() * 1000, rules.isDaylightSavings(instant), nameFormat.format(instant.atZone(zone))); transition = rules.nextTransition(instant); }//from w w w . j a va 2s.c o m return transitions; }
From source file:com.armeniopinto.time.ApplicationStarter.java
@RequestMapping("/time/{format}") public String time(@PathVariable String format) { final String time; if ("iso".equals(format)) { time = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mmX").withZone(ZoneOffset.UTC) .format(Instant.now()); } else if ("unix".equals(format)) { time = Long.toString(System.currentTimeMillis()); } else if ("pretty".equals(format)) { time = new Date().toString(); } else {// w ww. j a va 2s .c o m throw new IllegalArgumentException(String.format("Unkonwn date format: %s", format)); } return time; }
From source file:com.speedment.examples.social.JSONImage.java
public static List<JSONImage> parseFrom(String json) { final JSONObject container = (JSONObject) JSONValue.parse(json); final JSONArray array = (JSONArray) container.get("images"); final List<JSONImage> images = new ArrayList<>(); array.stream().forEach(o -> {/* ww w.ja va 2 s. com*/ final JSONObject obj = (JSONObject) o; final JSONImage img = new JSONImage(); final long time = Long.parseLong(obj.get("uploaded").toString()); final LocalDateTime ldt = LocalDateTime.ofEpochSecond(time / 1000L, (int) (time % 1000) * 1000, ZoneOffset.UTC); img.title = obj.get("title").toString(); img.description = obj.get("description").toString(); img.uploaded = ldt; img.uploader = JSONUser.parse((JSONObject) obj.get("uploader")); img.image = fromBase64(obj.get("img_data").toString()); images.add(img); }); Collections.sort(images, Comparator.reverseOrder()); return images; }
From source file:com.algodefu.yeti.web.rest.LocalDateTimeSerializer.java
@Override public void serialize(LocalDateTime value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { // jgen.writeString(value.format(dtf)); jgen.writeNumber(value.toInstant(ZoneOffset.UTC).toEpochMilli()); }
From source file:com.fizzed.stork.deploy.DeployHelper.java
static public String toVersionDateTime(long millis) { Instant instant = Instant.ofEpochMilli(millis); LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneOffset.UTC); return ldt.format(versionDateTimeFormatter); }
From source file:fi.helsinki.opintoni.service.TimeService.java
public String nowUTCAsString() { ZonedDateTime utc = ZonedDateTime.now(ZoneOffset.UTC); return utc.format(DateTimeFormatter.ISO_INSTANT); }
From source file:com.jernejerin.traffic.helper.TripOperations.java
/** * Parses and validates a trip for erroneous values. It first checks, if parsed string contains * 17 values. If it does not, it returns null. * * If the value is considered erroneous, it is set to the following values: * - primitive types: MIN_VALUE/* w ww . ja v a 2 s . co m*/ * - objects: null * * @param tripValues comma delimited string representing Trip to check * @param timestampReceived Timestamp when the event was received * @param id id of the event received * @return a Trip with erroneous values set to MIN_VALUE, or null if whole trip was malformed */ public static Trip parseValidateTrip(String tripValues, long timestampReceived, int id) { // LOGGER.log(Level.INFO, "Started parsing and validating trip = " + // tripValues + " from thread = " + Thread.currentThread()); // our returned trip Trip trip = new Trip(); // values are comma separated String[] tripSplit = tripValues.split(","); // if we do not have 17 values, then return null if (tripSplit.length != 17) return null; // check for correct values and then set them trip.setId(id); trip.setMedallion(tryParseMD5(tripSplit[0], null)); trip.setHackLicense(tryParseMD5(tripSplit[1], null)); trip.setPickupDatetime(tryParseDateTime(tripSplit[2], null)); trip.setDropOffDatetime(tryParseDateTime(tripSplit[3], null)); trip.setDropOffTimestamp( trip.getDropOffDatetime() != null ? trip.getDropOffDatetime().toEpochSecond(ZoneOffset.UTC) * 1000 : 0); trip.setTripTime(NumberUtils.toInt(tripSplit[4], Integer.MIN_VALUE)); trip.setTripDistance(NumberUtils.toFloat(tripSplit[5], Integer.MIN_VALUE)); trip.setPickupLongitude(tryLongitude(tripSplit[6], Float.MIN_VALUE)); trip.setPickupLatitude(tryLatitude(tripSplit[7], Float.MIN_VALUE)); trip.setDropOffLongitude(tryLongitude(tripSplit[8], Float.MIN_VALUE)); trip.setDropOffLatitude(tryLatitude(tripSplit[9], Float.MIN_VALUE)); trip.setPaymentType(tryPayment(tripSplit[10], null)); trip.setFareAmount(NumberUtils.toFloat(tripSplit[11], Float.MIN_VALUE)); trip.setSurcharge(NumberUtils.toFloat(tripSplit[12], Float.MIN_VALUE)); trip.setMtaTax(NumberUtils.toFloat(tripSplit[13], Float.MIN_VALUE)); trip.setTipAmount(NumberUtils.toFloat(tripSplit[14], Float.MIN_VALUE)); trip.setTollsAmount(NumberUtils.toFloat(tripSplit[15], Float.MIN_VALUE)); trip.setTotalAmount(NumberUtils.toFloat(tripSplit[16], Float.MIN_VALUE)); trip.setTimestampReceived(timestampReceived); // does the coordinate for pickup location lie inside grid if (Cell.inGrid(trip.getPickupLatitude(), trip.getPickupLongitude()) && Cell.inGrid(trip.getDropOffLatitude(), trip.getDropOffLongitude())) { trip.setRoute250(new Route(new Cell250(trip.getPickupLatitude(), trip.getPickupLongitude()), new Cell250(trip.getDropOffLatitude(), trip.getDropOffLongitude()))); trip.setRoute500(new Route(new Cell500(trip.getPickupLatitude(), trip.getPickupLongitude()), new Cell500(trip.getDropOffLatitude(), trip.getDropOffLongitude()))); } // LOGGER.log(Level.INFO, "Finished parsing and validating trip = " + // trip.toString() + " from thread = " + Thread.currentThread()); return trip; }
From source file:de.dentrassi.pm.aspect.common.CoreAspectFactory.java
private static void makeMetadata(final Extractor.Context context, final Map<String, String> metadata) throws IOException { metadata.put(KEY_NAME, context.getName()); metadata.put(KEY_EXT, FilenameUtils.getExtension(context.getName())); metadata.put(KEY_BASENAME, FilenameUtils.getBaseName(context.getName())); metadata.put(KEY_ISO_TIMESTAMP, context.getCreationTimestamp().toString()); metadata.put(KEY_TIMESTAMP,/*from w w w .ja v a2 s .c om*/ TIMESTAMP_FORMATTER.format(context.getCreationTimestamp().atOffset(ZoneOffset.UTC))); }
From source file:com.fizzed.stork.deploy.DeployHelper.java
static public String toFriendlyDateTime(long millis) { Instant instant = Instant.ofEpochMilli(millis); LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneOffset.UTC); return ldt.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME); }