List of usage examples for java.time ZoneId systemDefault
public static ZoneId systemDefault()
From source file:Main.java
public static LocalDate toLocalDate(Date date) { Date lDate = new Date(date.getTime()); return lDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); }
From source file:Main.java
public static LocalDate getLocalDateFromDate(Date date) { return LocalDateTime.ofInstant(new Date(date.getTime()).toInstant(), ZoneId.systemDefault()).toLocalDate(); }
From source file:Main.java
/** * Checks if the type of the given date. Possible return values are standard * time, the date when to switch to daylight saving time (in Europe the last * Sunday in March), daylight saving time or the date when to switch back to * standard time (in Europe the last Sunday in October). * /*from www. java 2s.c om*/ * @return DayType * @param cal * Date to check, cannot be null */ public static DayType getDSTType(LocalDate cal) { DayType status = DayType.DAYLIGHT_SAVING_TIME; LocalDateTime testDate = cal.atStartOfDay(); ZonedDateTime zdt = ZonedDateTime.of(testDate, ZoneId.systemDefault()); // Find type of day if (zdt.getZone().getRules().isDaylightSavings(testDate.toInstant(zdt.getOffset()))) status = DayType.DAYLIGHT_SAVING_TIME; else status = DayType.STANDARD_TIME; // Check the day after testDate = testDate.plusDays(1); zdt = ZonedDateTime.of(testDate, ZoneId.systemDefault()); // Find type of day after if (zdt.getZone().getRules().isDaylightSavings(testDate.toInstant(zdt.getOffset()))) { if (status != DayType.DAYLIGHT_SAVING_TIME) status = DayType.TO_DAYLIGHT_SAVING_TIME; } else { if (status == DayType.DAYLIGHT_SAVING_TIME) status = DayType.TO_STANDARD_TIME; } return status; }
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 ww w.j a va 2s . 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; } }
From source file:org.pr.nb.clocks.model.NBClock.java
public NBClock(String zoneId) { this.zoneId = ZoneId.of(zoneId, ZoneId.SHORT_IDS); zoneDateTime = ZonedDateTime.now(this.zoneId); homeZone = StringUtils.equals(zoneId, ZoneId.systemDefault().getId()); }
From source file:org.eclipse.smarthome.core.scheduler.CronHelper.java
/** * Returns CRON expression from the provided {@link Calendar} instance * * @param calendar the {@link Calendar} instance * @return the CRON expression//from w w w . j a v a 2 s . c o m * @throws NullPointerException * if {@code calendar} is null */ public static String createCronFromCalendar(Calendar calendar) { requireNonNull(calendar, "Calendar instance cannot be null"); LocalDateTime temporal = LocalDateTime.ofInstant(calendar.toInstant(), ZoneId.systemDefault()); return createCronFromTemporal(temporal); }
From source file:eu.hansolo.tilesfx.weather.Sun.java
/** * Returns an array of ZonedDateTime objects for sunrise and sunset in UTC. Means there * are no daylight saving time adjustments. * @param LATITUDE//from w w w .j a va2s .com * @param LONGITUDE * @return an array of ZonedDateTime objects for sunrise and sunset in UTC. */ public static ZonedDateTime[] getSunriseSunsetAt(final double LATITUDE, final double LONGITUDE) { return getSunriseSunsetAt(LATITUDE, LONGITUDE, ZoneId.systemDefault()); }
From source file:com.ewerk.prototype.persistence.converters.DateToLocalDateConverter.java
@Override public LocalDate convert(Date source) { if (source == null) { return null; }/*from w w w. j a va2 s .c o m*/ return source.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); }
From source file:defaultmethods.TimeClient.java
static ZoneId getZoneId(String zoneString) { try {// ww w. j ava 2 s . c o m return ZoneId.of(zoneString); } catch (DateTimeException e) { System.err.println("Invalid time zone: " + zoneString + "; using default time zone instead."); return ZoneId.systemDefault(); } }
From source file:com.ewerk.prototype.persistence.converters.LocalDateToDateConverter.java
@Override public Date convert(LocalDate localDate) { if (localDate == null) { return null; }//from www . j a v a 2 s . c o m return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); }