Java 8 ZonedDateTime - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ZonedDateTime class.

This code example shows how to use the following methods:getZone, toEpochSecond
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:toEpochSecond
    } 
 
    @JsonProperty 
    public long getEpochSeconds() 
    { 
        return date.toEpochSecond();
    } 
 
    @JsonProperty 
    public ZoneId getTimeZone()
    { 
        return date.getZone();
    } 
 
    public ZonedDateTime getDate()
    { 
        return date;
    } 
 
    @Override 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:toEpochSecond
            } 
 
            List<String> fields = new ArrayList<>(Splitter.on(" ").splitToList(currentLine));
 
            // Timestamps in file are delta encoded 
            long secondsSinceEpoch = date.toEpochSecond();
            secondsSinceEpoch += Integer.parseInt(fields.get(2));
            fields.set(2, String.valueOf(secondsSinceEpoch));
 
            return Joiner.on(" ").join(fields);
        } 
 
        @Override 
        public void close() 
        { 
            try { 
                reader.close();
            } 
            catch (IOException e) {
                throw Throwables.propagate(e);
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:toInstant
 
  @Override 
  public long convertToMillis(YearMonth value) {
    LocalDate localDate = toLocalDate(value);
    ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
    return zonedDateTime.toInstant().toEpochMilli();
  } 
 
  @Override 
  public YearMonth convertFromDate(Date ts) {
    return fromLocalDate(ts.toLocalDate());
  } 
 
  @Override 
  public Date convertToDate(YearMonth t) {
    return Date.valueOf(toLocalDate(t));
  } 
 
  @Override 
  public Object toJdbcType(Object value) { 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getZone
This code example shows how to use the following methods:toInstant
//        Instant valueAsInstant = Instant.ofEpochSecond(zonedValue.toEpochSecond()); 
//        int defaultTimezoneOffset = TimeZone.getDefault().getOffset(zonedValue.toEpochSecond() * MILLIS_IN_SECOND); 
//        int databaseTimezoneOffsetInSeconds = currentDatabaseZone.getRules().getOffset(valueAsInstant).getTotalSeconds(); 
//        int adjustment = defaultTimezoneOffset - databaseTimezoneOffsetInSeconds * MILLIS_IN_SECOND; 
    	 
    	final Date date = new Date(zonedValue.toInstant().toEpochMilli());
        return date;
    } 
 
    private static ZoneOffset getDefault() {
 
    	ZoneOffset zone = null;
        try { 
            try { 
                String id = System.getProperty("user.timezone");
                if (id != null) {
                    zone = ZoneOffset.of(id);
                } 
            } catch (RuntimeException ex) {
                zone = null;
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:toInstant
 
  @Override 
  public Timestamp convertToTimestamp(LocalDateTime t) {
 
    ZonedDateTime zonedDateTime = t.atZone(ZoneId.systemDefault());
    return Timestamp.from(zonedDateTime.toInstant());
  } 
 
  @Override 
  public Object toJdbcType(Object value) { 
    if (value instanceof Timestamp) return value;
    return convertToTimestamp((LocalDateTime)value);
  } 
 
  @Override 
  public LocalDateTime toBeanType(Object value) {
    if (value instanceof LocalDateTime) return (LocalDateTime)value;
    return convertFromTimestamp((Timestamp)value);
  } 
} 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:toInstant
        if (value != null) {
            if (calendar.isPresent()) {
                // We need to make a clone, because Calendar is not thread-safe 
                // and some JDBC drivers mutate it during time calculations 
                final Calendar calendarClone = (Calendar) calendar.get().clone();
                statement.setTimestamp(position, new Timestamp(value.toInstant().toEpochMilli()), calendarClone);
            } else { 
                statement.setTimestamp(position, new Timestamp(value.toInstant().toEpochMilli()));
            } 
        } else { 
            statement.setNull(position, Types.TIMESTAMP);
        } 
    } 
} 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:hashCode
  ZonedDateTime warmUp = ZonedDateTime.now();
 
  @Test
  public void testConvertToMillis() throws Exception {
 
    warmUp.hashCode();
 
    long now = System.currentTimeMillis();
    long toMillis = type.convertToMillis(ZonedDateTime.now());
 
    assertTrue(toMillis - now < 10);
 
  } 
 
  @Test
  public void testConvertFromTimestamp() throws Exception {
 
    Timestamp now = new Timestamp(System.currentTimeMillis());
 
    ZonedDateTime val1 = type.convertFromTimestamp(now);
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:toInstant
         
    	ZoneOffset currentDatabaseZone = getDatabaseZone() == null ? getDefault() : getDatabaseZone();
    	 
    	ZonedDateTime zdt = ldt.atZone(currentDatabaseZone);
         
        final Timestamp timestamp = new Timestamp(zdt.toInstant().toEpochMilli());
        return timestamp;
    } 
     
    private static ZoneOffset getDefault() {
 
    	ZoneOffset zone = null;
        try { 
            try { 
                String id = System.getProperty("user.timezone");
                if (id != null) {
                    zone = ZoneOffset.of(id);
                } 
            } catch (RuntimeException ex) {
                zone = null;
4
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Java 8 ZonedDateTime Methods: