Java Code Examples for java.util.TimeZone#toZoneId()
The following examples show how to use
java.util.TimeZone#toZoneId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlDateTimeUtils.java From flink with Apache License 2.0 | 5 votes |
/** * Do addition on timestamp. * * @param ts the timestamp. * @param days days count you want to add. * @return datetime string. */ public static String dateAdd(long ts, int days, TimeZone tz) { ZoneId zoneId = tz.toZoneId(); Instant instant = Instant.ofEpochMilli(ts); ZonedDateTime zdt = ZonedDateTime.ofInstant(instant, zoneId); long resultTs = zdt.plusDays(days).toInstant().toEpochMilli(); return dateFormat(resultTs, DATE_FORMAT_STRING, tz); }
Example 2
Source File: RollingFileWriter.java From swage with Apache License 2.0 | 5 votes |
/** * Create a RollingFileWriter as specified * * @param directory Path where the log files will be created * @param name Base name to use for log files * @param zone Time zone of timestamps on rolling file names * @param minuteRotation If true, rotate logs every minute, if false rotate every hour */ RollingFileWriter(Path directory, String name, TimeZone zone, boolean minuteRotation) { if (directory == null) { throw new IllegalArgumentException("Directory required"); } if (name == null) { throw new IllegalArgumentException("File base name required"); } if (zone == null) { throw new IllegalArgumentException("Time zone required"); } this.directory = directory; this.baseName = name; this.timeZone = zone.toZoneId(); final String formatPattern = (minuteRotation ? ".yyyy-MM-dd-HH-mm" : ".yyyy-MM-dd-HH"); this.format = DateTimeFormatter.ofPattern(formatPattern); if (minuteRotation) { rollInterval = ChronoUnit.SECONDS; } else { rollInterval = ChronoUnit.HOURS; } // Set to roll immediately on first write, to ensure file is created this.rollAt = Instant.now().truncatedTo(rollInterval); }
Example 3
Source File: EnvironmentZonedDateTimeStrategy.java From freemarker-java-8 with Apache License 2.0 | 5 votes |
@Override public ZoneId getZoneId(ZoneId input) { Environment env = Environment.getCurrentEnvironment(); if (env == null) { throw new IllegalStateException(getClass().getName() + " called outside of a template processing thread"); } final TimeZone timeZone = env.getTimeZone(); if (timeZone == null) { throw new NullPointerException("Current Environment has no TimeZone set!"); } return timeZone.toZoneId(); }
Example 4
Source File: DatabaseImpl.java From jackcess with Apache License 2.0 | 5 votes |
private void setZoneInfo(TimeZone newTimeZone, ZoneId newZoneId) { if(newTimeZone != null) { newZoneId = newTimeZone.toZoneId(); } else if(newZoneId != null) { newTimeZone = TimeZone.getTimeZone(newZoneId); } else { newTimeZone = getDefaultTimeZone(); newZoneId = newTimeZone.toZoneId(); } _timeZone = newTimeZone; _zoneId = newZoneId; }
Example 5
Source File: SqlDateTimeUtils.java From flink with Apache License 2.0 | 5 votes |
/** * Do addition on timestamp. * * @param ts the timestamp. * @param days days count you want to add. * @return datetime string. */ public static String dateAdd(long ts, int days, TimeZone tz) { ZoneId zoneId = tz.toZoneId(); Instant instant = Instant.ofEpochMilli(ts); ZonedDateTime zdt = ZonedDateTime.ofInstant(instant, zoneId); long resultTs = zdt.plusDays(days).toInstant().toEpochMilli(); return dateFormat(resultTs, DATE_FORMAT_STRING, tz); }
Example 6
Source File: MetricsStreamCallback.java From graphouse with Apache License 2.0 | 4 votes |
public MetricsStreamCallback(List<Metric> metrics, TimeZone clickHouseTimeZone) { this(metrics, clickHouseTimeZone.toZoneId(), LocalDate.now()); }
Example 7
Source File: ServletRequestMethodArgumentResolver.java From lams with GNU General Public License v2.0 | 4 votes |
public static Object resolveZoneId(HttpServletRequest request) { TimeZone timeZone = RequestContextUtils.getTimeZone(request); return (timeZone != null ? timeZone.toZoneId() : ZoneId.systemDefault()); }
Example 8
Source File: ServletRequestMethodArgumentResolver.java From spring4-understanding with Apache License 2.0 | 4 votes |
public static Object resolveZoneId(HttpServletRequest request) { TimeZone timeZone = RequestContextUtils.getTimeZone(request); return (timeZone != null ? timeZone.toZoneId() : ZoneId.systemDefault()); }
Example 9
Source File: GtfsStatisticsService.java From gtfs-validator with MIT License | 4 votes |
private ZoneId getTimeZone(){ CalendarService calendarService = CalendarServiceDataFactoryImpl.createService(gtfsDao); TimeZone tz = calendarService.getTimeZoneForAgencyId(gtfsDao.getAllAgencies().iterator().next().getId()); return tz.toZoneId(); }
Example 10
Source File: OrienteerWebSession.java From Orienteer with Apache License 2.0 | 4 votes |
public ZoneId getClientZoneId() { TimeZone timeZone = getClientInfo().getProperties().getTimeZone(); return timeZone != null ? timeZone.toZoneId() : ZoneId.systemDefault(); }
Example 11
Source File: SqlDateTimeUtils.java From flink with Apache License 2.0 | 3 votes |
/** * NOTE: * (1). JDK relies on the operating system clock for time. * Each operating system has its own method of handling date changes such as * leap seconds(e.g. OS will slow down the clock to accommodate for this). * (2). DST(Daylight Saving Time) is a legal issue, governments changed it * over time. Some days are NOT exactly 24 hours long, it could be 23/25 hours * long on the first or last day of daylight saving time. * JDK can handle DST correctly. * TODO: * carefully written algorithm can improve the performance */ public static int dateDiff(long t1, long t2, TimeZone tz) { ZoneId zoneId = tz.toZoneId(); LocalDate ld1 = Instant.ofEpochMilli(t1).atZone(zoneId).toLocalDate(); LocalDate ld2 = Instant.ofEpochMilli(t2).atZone(zoneId).toLocalDate(); return (int) ChronoUnit.DAYS.between(ld2, ld1); }
Example 12
Source File: SqlDateTimeUtils.java From flink with Apache License 2.0 | 3 votes |
/** * Do subtraction on date string. * * @param ts the timestamp. * @param days days count you want to subtract. * @param tz time zone of the date time string * @return datetime string. */ public static String dateSub(long ts, int days, TimeZone tz) { ZoneId zoneId = tz.toZoneId(); Instant instant = Instant.ofEpochMilli(ts); ZonedDateTime zdt = ZonedDateTime.ofInstant(instant, zoneId); long resultTs = zdt.minusDays(days).toInstant().toEpochMilli(); return dateFormat(resultTs, DATE_FORMAT_STRING, tz); }
Example 13
Source File: SqlDateTimeUtils.java From flink with Apache License 2.0 | 3 votes |
/** * NOTE: * (1). JDK relies on the operating system clock for time. * Each operating system has its own method of handling date changes such as * leap seconds(e.g. OS will slow down the clock to accommodate for this). * (2). DST(Daylight Saving Time) is a legal issue, governments changed it * over time. Some days are NOT exactly 24 hours long, it could be 23/25 hours * long on the first or last day of daylight saving time. * JDK can handle DST correctly. * TODO: * carefully written algorithm can improve the performance */ public static int dateDiff(long t1, long t2, TimeZone tz) { ZoneId zoneId = tz.toZoneId(); LocalDate ld1 = Instant.ofEpochMilli(t1).atZone(zoneId).toLocalDate(); LocalDate ld2 = Instant.ofEpochMilli(t2).atZone(zoneId).toLocalDate(); return (int) ChronoUnit.DAYS.between(ld2, ld1); }
Example 14
Source File: SqlDateTimeUtils.java From flink with Apache License 2.0 | 3 votes |
/** * Do subtraction on date string. * * @param ts the timestamp. * @param days days count you want to subtract. * @param tz time zone of the date time string * @return datetime string. */ public static String dateSub(long ts, int days, TimeZone tz) { ZoneId zoneId = tz.toZoneId(); Instant instant = Instant.ofEpochMilli(ts); ZonedDateTime zdt = ZonedDateTime.ofInstant(instant, zoneId); long resultTs = zdt.minusDays(days).toInstant().toEpochMilli(); return dateFormat(resultTs, DATE_FORMAT_STRING, tz); }
Example 15
Source File: DateUtil.java From blade-tool with GNU Lesser General Public License v3.0 | 2 votes |
/** * 转换成java8 时间 * * @param calendar 日历 * @return LocalDateTime */ public static LocalDateTime fromCalendar(final Calendar calendar) { TimeZone tz = calendar.getTimeZone(); ZoneId zid = tz == null ? ZoneId.systemDefault() : tz.toZoneId(); return LocalDateTime.ofInstant(calendar.toInstant(), zid); }