Example usage for java.time ZonedDateTime format

List of usage examples for java.time ZonedDateTime format

Introduction

In this page you can find the example usage for java.time ZonedDateTime format.

Prototype

@Override 
public String format(DateTimeFormatter formatter) 

Source Link

Document

Formats this date-time using the specified formatter.

Usage

From source file:Main.java

public static void main(String[] argv) {
    DateTimeFormatter format = DateTimeFormatter.ofPattern("MMM dd yyyy hh:mm a z");
    ZonedDateTime arrivalDate = ZonedDateTime.now();
    String landing = arrivalDate.format(format);
    System.out.printf("Arriving at :  %s %n", landing);
}

From source file:Main.java

public static void main(String[] argv) {
    LocalDate ld = LocalDate.now();
    String ldStr = ld.format(DateTimeFormatter.ISO_DATE);
    System.out.println("Local  Date: " + ldStr);

    OffsetDateTime odt = OffsetDateTime.now();
    String odtStr = odt.format(DateTimeFormatter.ISO_DATE);
    System.out.println("Offset  Datetime: " + odtStr);

    ZonedDateTime zdt = ZonedDateTime.now();
    String zdtStr = zdt.format(DateTimeFormatter.ISO_DATE);
    System.out.println("Zoned  Datetime: " + zdtStr);
}

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime dateTime = ZonedDateTime.from(ZonedDateTime.now());
    String s = dateTime.format(DateTimeFormatter.ISO_DATE_TIME);
    System.out.println(s);/*ww w.ja v a2s  . co  m*/
}

From source file:Main.java

public static void main(String[] args) {
    DateTimeFormatter format = DateTimeFormatter.ofPattern("MMM d yyyy  hh:mm a");
    LocalDateTime leaving = LocalDateTime.of(2013, Month.JULY, 20, 19, 30);

    // Leaving from San Francisco on July 20, 2013, at 7:30 p.m.

    ZoneId leavingZone = ZoneId.of("America/Los_Angeles");
    ZonedDateTime departure = ZonedDateTime.of(leaving, leavingZone);

    String out1 = departure.format(format);
    System.out.printf("LEAVING:  %s (%s)%n", out1, leavingZone);

    // Flight is 10 hours and 50 minutes, or 650 minutes
    ZoneId arrivingZone = ZoneId.of("Asia/Tokyo");
    ZonedDateTime arrival = departure.withZoneSameInstant(arrivingZone).plusMinutes(650);

    String out2 = arrival.format(format);
    System.out.printf("ARRIVING: %s (%s)%n", out2, arrivingZone);

}

From source file:Main.java

public static void main(String[] args) {
    LocalTime now = LocalTime.now();
    LocalTime currentTimeInLosAngeles = LocalTime.now(ZoneId.of("America/Los_Angeles"));
    System.out.println(String.format("now is %s and in LA is %s", now, currentTimeInLosAngeles));

    ZoneId leavingZone = ZoneId.of("Asia/Tel_Aviv");
    ZoneId arrivingZone = ZoneId.of("America/New_York");

    LocalDateTime leaving = LocalDateTime.of(2014, Month.JULY, 16, 23, 00);
    ZonedDateTime departure = ZonedDateTime.of(leaving, leavingZone);

    ZonedDateTime arrival = departure.withZoneSameInstant(arrivingZone).plusHours(11).plusMinutes(51);

    DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-d  HH:mm");
    System.out.println(String.format("Departure: %s", departure.format(format)));
    System.out.println(String.format("Arrival: %s", arrival.format(format)));
}

From source file:io.stallion.utils.GeneralUtils.java

@Deprecated
public static String slugifyDate(ZonedDateTime date) {
    return date.format(SLUG_FORMAT);
}

From source file:org.openrepose.filters.custom.extractdeviceid.ExtractDeviceIdFilter.java

static String getRetryString(Header[] headers, int statusCode) {
    String rtn;//from w  w  w . j a va  2  s.  co m
    Object[] retryHeaders = Arrays.stream(headers).filter(header -> header.getName().equals(RETRY_AFTER))
            .toArray();
    if (retryHeaders.length < 1) {
        LOG.info("Missing {} header on Auth Response status code: {}", RETRY_AFTER, statusCode);
        final ZonedDateTime zdt = ZonedDateTime.now(Clock.systemUTC());
        zdt.plusSeconds(5);
        rtn = zdt.format(RFC_1123_DATE_TIME);
    } else {
        rtn = ((Header) retryHeaders[0]).getValue();
    }
    return rtn;
}

From source file:alfio.util.EventUtil.java

public static String getGoogleCalendarURL(Event event, TicketCategory category, String description) {
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyMMdd'T'HHmmss");
    ZonedDateTime validityStart = Optional.ofNullable(category).map(TicketCategory::getTicketValidityStart)
            .map(d -> d.withZoneSameInstant(event.getZoneId())).orElse(event.getBegin());
    ZonedDateTime validityEnd = Optional.ofNullable(category).map(TicketCategory::getTicketValidityEnd)
            .map(d -> d.withZoneSameInstant(event.getZoneId())).orElse(event.getEnd());
    return UriComponentsBuilder.fromUriString("https://www.google.com/calendar/event")
            .queryParam("action", "TEMPLATE")
            .queryParam("dates", validityStart.format(formatter) + "/" + validityEnd.format(formatter))
            .queryParam("ctz", event.getTimeZone()).queryParam("text", event.getDisplayName())
            .queryParam("location", event.getLocation()).queryParam("detail", description).toUriString();
}

From source file:io.stallion.utils.GeneralUtils.java

@Deprecated
public static String formatLocalDateFromZonedDate(ZonedDateTime date, String formatPattern) {
    if (date == null) {
        return "";
    }//  w w  w .ja v  a2s.  com

    ZonedDateTime localDt = date.withZoneSameInstant(Context.getSettings().getTimeZoneId());

    DateTimeFormatter formatter;
    if (StringUtils.isEmpty(formatPattern)) {
        formatter = DEFAULT_FORMAT;
    } else if ("iso".equals(formatPattern.toLowerCase())) {
        formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
    } else {
        formatter = DateTimeFormatter.ofPattern(formatPattern);
    }
    return localDt.format(formatter);
}

From source file:fi.helsinki.opintoni.service.TimeService.java

public String nowUTCAsString() {
    ZonedDateTime utc = ZonedDateTime.now(ZoneOffset.UTC);
    return utc.format(DateTimeFormatter.ISO_INSTANT);
}