Example usage for java.util Date from

List of usage examples for java.util Date from

Introduction

In this page you can find the example usage for java.util Date from.

Prototype

public static Date from(Instant instant) 

Source Link

Document

Obtains an instance of Date from an Instant object.

Usage

From source file:eu.off.db.entity.MemberTest.java

@Test
public void BuildFullMember() {

    LocalDateTime dateTime = LocalDateTime.of(1978, Month.APRIL, 4, 0, 0);
    Date birthday = Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant());

    Member aMember = new MemberBuilder(LAST_NAME, FIRST_NAME, STREET, ZIP_CODE, PLACE, COUNTRY, birthday,
            GENDER, NATIONALITY).email(EMAIL).phone(PHONE).portablePhone(PORTABLE_PHONE).memberSince(birthday)
                    .licenseSince(birthday).build();

    assertThat(aMember.getEmail().equals(EMAIL));
    assertThat(aMember.getPhone().equals(PHONE));
    assertThat(aMember.getPortablePhone().equals(PORTABLE_PHONE));
    assertThat(aMember.getMemberSince().equals(birthday));
    assertThat(aMember.getLicenseSince().equals(birthday));

}

From source file:org.sakaiproject.assignment.persistence.AssignmentRepositoryImpl.java

@Override
@Transactional/*from   ww  w. j av a2s .  c  o  m*/
public void updateAssignment(Assignment assignment) {
    assignment.setDateModified(Date.from(Instant.now()));
    sessionFactory.getCurrentSession().update(assignment);
}

From source file:org.apdplat.superword.system.AntiRobotFilter.java

public static void main(String[] args) {
    LocalDateTime timePoint = LocalDateTime.now().minusDays(1);
    String date = SIMPLE_DATE_FORMAT.format(Date.from(timePoint.atZone(ZoneId.systemDefault()).toInstant()));
    System.out.println(date);/*w w w.ja  v a 2s  . c  om*/
}

From source file:org.helioviewer.jhv.plugins.hekplugin.HEKPlugin.java

@Override
public void render(GL2 gl, PluginLayer _imageParams) {
    if (isVisible()) {
        LocalDateTime in = Plugins.SINGLETON.getCurrentDateTime();
        if (in != null) {
            Date currentDate = Date.from(in.atZone(ZoneId.systemDefault()).toInstant());
            List<HEKEvent> toDraw = HEKCache.getSingletonInstance().getModel().getActiveEvents(currentDate);
            if (toDraw != null && toDraw.size() > 0) {
                gl.glDisable(GL2.GL_TEXTURE_2D);
                gl.glEnable(GL2.GL_CULL_FACE);
                gl.glEnable(GL2.GL_LINE_SMOOTH);
                gl.glEnable(GL2.GL_BLEND);

                for (HEKEvent evt : toDraw)
                    drawPolygon(gl, evt, currentDate);

                gl.glDisable(GL2.GL_LINE_SMOOTH);

                gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
                gl.glDisable(GL2.GL_DEPTH_TEST);
                gl.glEnable(GL2.GL_TEXTURE_2D);
                gl.glColor4f(1.0f, 1.0f, 1.0f, 1);

                for (HEKEvent evt : toDraw)
                    drawIcon(gl, evt, currentDate);

                gl.glDisable(GL2.GL_TEXTURE_2D);
                gl.glDisable(GL2.GL_BLEND);
                gl.glEnable(GL2.GL_DEPTH_TEST);
                gl.glDisable(GL2.GL_CULL_FACE);
            }//w  w  w  .  j av a2s.  c  o m
        }
    }
}

From source file:org.wallride.web.support.RssFeedView.java

@SuppressWarnings("unchecked")
@Override/*from  w w  w . java  2  s . c o m*/
protected List<Item> buildFeedItems(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Set<Article> articles = (Set<Article>) model.get("articles");
    List<Item> items = new ArrayList<>(articles.size());
    for (Article article : articles) {
        Item item = new Item();
        item.setTitle(article.getTitle());
        item.setPubDate(Date.from(article.getDate().atZone(ZoneId.systemDefault()).toInstant()));
        Description description = new Description();
        description.setType("text/html");
        description.setValue(article.getBody());
        item.setDescription(description);
        item.setLink(link(article));
        items.add(item);
    }
    return items;
}

From source file:com.example.jpa.UserEntity.java

@PrePersist
public void setCreatedAt() {
    final ZonedDateTime now = ZonedDateTime.now();
    final Instant instant = now.toInstant();
    this.createdAt = Date.from(instant);
}

From source file:com.netflix.metacat.connector.hive.converters.HiveConnectorInfoConverter.java

/**
 * Converts epoch time to Date./*from   w  ww.  java2 s. c  o m*/
 *
 * @param seconds time in seconds
 * @return Date
 */
public static Date epochSecondsToDate(final long seconds) {
    return Date.from(Instant.ofEpochSecond(seconds));
}

From source file:org.sonatype.nexus.tasklog.TaskLogCleanup.java

void cleanup() {
    String taskLogsHome = getTaskLogHome();

    if (taskLogsHome == null) {
        // we are forgiving if the task logs home is not defined. Just log a message with a call to action.
        log.warn(//from  www  . jav a  2 s . co  m
                "Unable to cleanup task log files. Please check that the 'tasklogfile' appender exists in logback.xml");
        return;
    }

    File logFilesHome = new File(taskLogsHome);

    log.info("Cleaning up log files in {} older than {} days", logFilesHome.getAbsolutePath(), numberOfDays);

    LocalDate now = LocalDate.now().minusDays(numberOfDays);
    Date thresholdDate = Date.from(now.atStartOfDay(ZoneId.systemDefault()).toInstant());
    AgeFileFilter ageFileFilter = new AgeFileFilter(thresholdDate);
    Iterator<File> filesToDelete = iterateFiles(logFilesHome, ageFileFilter, ageFileFilter);
    filesToDelete.forEachRemaining(f -> {
        try {
            forceDelete(f);
            log.info("Removed task log file {}", f.toString());
        } catch (IOException e) { // NOSONAR
            log.error("Unable to delete task file {}. Message was {}.", f.toString(), e.getMessage());
        }
    });
}

From source file:com.vmware.photon.controller.api.client.resource.TenantsApiTest.java

@Test
public void testCreate() throws IOException {
    Task responseTask = new Task();
    responseTask.setId("12345");
    responseTask.setState("QUEUED");
    responseTask.setQueuedTime(Date.from(Instant.now()));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(responseTask);

    setupMocks(serializedTask, HttpStatus.SC_CREATED);

    TenantsApi tenantsApi = new TenantsApi(restClient);

    Task task = tenantsApi.create("foo");
    assertEquals(task, responseTask);//ww w .ja va2  s  .  c  o m
}

From source file:com.example.oauth.AccessToken.java

@Override
public Date getExpiration() {
    return Date.from(expiration.toInstant());
}