Example usage for java.time ZoneOffset UTC

List of usage examples for java.time ZoneOffset UTC

Introduction

In this page you can find the example usage for java.time ZoneOffset UTC.

Prototype

ZoneOffset UTC

To view the source code for java.time ZoneOffset UTC.

Click Source Link

Document

The time-zone offset for UTC, with an ID of 'Z'.

Usage

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime z = ZonedDateTime.ofInstant(LocalDateTime.now(), ZoneOffset.UTC, ZoneId.systemDefault());

    System.out.println(z);//from  w  w  w.j a va2  s. co  m

}

From source file:Main.java

public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.of(LocalDate.now(), LocalTime.NOON, ZoneOffset.UTC);

    System.out.println(o);/*from ww w  .j av a2  s .co  m*/
}

From source file:Main.java

public static void main(String[] args) {
    LocalDateTime a = LocalDateTime.of(2014, 6, 30, 12, 00);

    OffsetDateTime b = a.atOffset(ZoneOffset.UTC);
    System.out.println(b);/*from  w w w .  j  a va2 s  . c  om*/
}

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime z = ZonedDateTime.ofLocal(LocalDateTime.now(), ZoneId.systemDefault(), ZoneOffset.UTC);

    System.out.println(z);/*from   www.  ja  v a2  s .c o  m*/

}

From source file:org.zaproxy.admin.PendingAddOnReleases.java

public static void main(String[] args) throws Exception {
    LocalDate now = LocalDate.now(ZoneOffset.UTC);
    boolean showChanges = true;

    ZapXmlConfiguration zapVersions = new ZapXmlConfiguration(Paths.get(ZAP_VERSIONS_FILE_NAME).toFile());
    AddOnCollection addOnCollection = new AddOnCollection(zapVersions, AddOnCollection.Platform.daily);

    zapVersions.setExpressionEngine(new XPathExpressionEngine());

    Set<AddOnData> addOns = getAllAddOns();
    int totalAddOns = addOns.size();

    Set<AddOnData> unreleasedAddOns = new TreeSet<>();
    Set<AddOnData> unchangedAddOns = new TreeSet<>();

    for (Iterator<AddOnData> it = addOns.iterator(); it.hasNext();) {
        AddOnData addOnData = it.next();
        AddOn addOn = addOnCollection.getAddOn(addOnData.getId());
        if (addOn == null) {
            unreleasedAddOns.add(addOnData);
            it.remove();/*from  w  w  w  .j av  a2s.  com*/
        } else if (addOn.getVersion().compareTo(addOnData.getVersion()) >= 0) {
            it.remove();
        } else if (addOnData.getChanges().isEmpty()) {
            unchangedAddOns.add(addOnData);
            it.remove();
        }
    }

    if (!unreleasedAddOns.isEmpty()) {
        System.out.println("=============================");
        System.out.println("Unreleased add-ons (" + unreleasedAddOns.size() + " of " + totalAddOns + ")");
        System.out.println("=============================");
        for (AddOnData addOn : unreleasedAddOns) {
            System.out.println(addOn.getStatus() + "\t" + addOn.getName() + " v" + addOn.getVersion());
        }
        System.out.println("=============================\n");
    }

    if (!addOns.isEmpty()) {
        System.out.println("=======================================");
        System.out.println("New versions pending release (" + addOns.size() + " of " + totalAddOns + ")");
        System.out.println("=======================================");
        Status currentStatus = null;
        for (AddOnData addOn : addOns) {
            if (currentStatus != addOn.getStatus()) {
                currentStatus = addOn.getStatus();
                System.out.println(currentStatus);
            }
            LocalDate releaseDate = LocalDate.parse(zapVersions.getString("/addon_" + addOn.getId() + "/date"));
            System.out.println("  * " + addOn.getName() + " v" + addOn.getVersion() + " ("
                    + Period.between(releaseDate, now) + ")");

            if (showChanges) {
                for (String change : addOn.getChanges()) {
                    System.out.println("       - " + change);
                }
            }
        }
        System.out.println("=======================================\n");
    }

    if (!unchangedAddOns.isEmpty()) {
        System.out.println("=============================");
        System.out.println("Unchanged add-ons (" + unchangedAddOns.size() + " of " + totalAddOns + ")");
        System.out.println("=============================");
        for (AddOnData addOn : unchangedAddOns) {
            System.out.println(addOn.getStatus() + "\t" + addOn.getName() + " v" + addOn.getVersion());
        }
        System.out.println("=============================\n");
    }
}

From source file:com.teslagov.joan.example.Main.java

public static void main(String[] args) throws Exception {
    Properties properties = ArcPropertiesFactory.createArcProperties();

    ArcConfiguration arcConfiguration = arcConfig().arcPortalConfiguration(portalConfig()
            .portalAdminUsername(properties.getString(ArcProperties.PORTAL_ADMIN_USERNAME))
            .portalAdminPassword(properties.getString(ArcProperties.PORTAL_ADMIN_PASSWORD))
            .portalUrl(properties.getString(ArcProperties.PORTAL_URL))
            .portalPort(properties.getInteger(ArcProperties.PORTAL_PORT))
            .portalContextPath(properties.getString(ArcProperties.PORTAL_CONTEXT_PATH))
            .portalIsUsingWebAdaptor(properties.getBoolean(ArcProperties.PORTAL_IS_USING_WEB_ADAPTOR)).build())
            .build();//from w  ww  .j  a  va  2s.  c  om

    HttpClient httpClient = TrustingHttpClientFactory.createVeryUnsafePortalHttpClient(arcConfiguration, null);

    ArcPortalConfiguration arcPortalConfiguration = arcConfiguration.getArcPortalConfiguration();

    ArcPortalApi arcPortalApi = new ArcPortalApi(httpClient, arcPortalConfiguration, ZoneOffset.UTC,
            new TokenManager(new TokenRefresher(new PortalTokenFetcher(httpClient, arcPortalConfiguration),
                    ZoneOffset.UTC)));

    UserListResponse userListResponse = arcPortalApi.userApi.fetchUsers();
    if (userListResponse.isSuccess()) {
        List<UserResponseModel> users = userListResponse.users;
        users.forEach(u -> logger.debug("User {}", u));
    }

    String username = UUID.randomUUID().toString();
    String id = null;
    String publishedId = null;
    String groupId = null;

    try {
        groupId = createGroupExample(arcPortalApi);

        createNewUserExample(arcPortalApi, username);

        id = uploadItemExample(arcPortalApi, username);

        String analyzeResponse = arcPortalApi.itemApi.analyzeItem(id);

        publishedId = publishItemExample(arcPortalApi, id, username, analyzeResponse);

        shareItemExample(arcPortalApi, publishedId, username, groupId);

        deleteItemExample(arcPortalApi, id, username);

        deleteItemExample(arcPortalApi, publishedId, username);

        removeUserExample(arcPortalApi, username);

        deleteGroupExample(arcPortalApi, groupId);
    } catch (Exception e) {
        if (id != null) {
            arcPortalApi.itemApi.deleteItem(id, username);
        }

        if (publishedId != null) {
            arcPortalApi.itemApi.deleteItem(publishedId, username);
        }

        if (groupId != null) {
            arcPortalApi.groupApi.deleteGroup(groupId);
        }

        arcPortalApi.userApi.deleteUser(username);

        logger.debug("Exception occured {}", e.getMessage());
    }
}

From source file:Main.java

public static Date fromLocalDateInUTC(LocalDate date) {
    return Date.from(date.atStartOfDay().toInstant(ZoneOffset.UTC));
}

From source file:Main.java

/**
 * @param date//from  w  w w.  j  a  va  2 s . c  om
 *            Date for which seconds since the epoch date is to be calculated
 * @return Number of seconds after the unix epoch date equivalent to the given date
 */
public static Integer secondsSinceUnixEpoch(final LocalDateTime date) {
    if (date == null) {
        return null;
    }
    final Long timeInSeconds = Long.valueOf(date.toEpochSecond(ZoneOffset.UTC));
    return Integer.valueOf(timeInSeconds.intValue());
}

From source file:Main.java

public static ZonedDateTime getDateTime(Timestamp timestamp) {
    return timestamp != null
            ? ZonedDateTime.ofInstant(Instant.ofEpochMilli(timestamp.getTime()), ZoneOffset.UTC)
            : null;// www  . ja  v a  2 s .  com
}

From source file:org.openhab.binding.gardena.internal.util.DateUtils.java

/**
 * Converts a string to a Date, trying different date formats used by Gardena.
 *//*from  w  w w.ja  v  a2s.c o  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;
    }

}