Example usage for java.time Instant now

List of usage examples for java.time Instant now

Introduction

In this page you can find the example usage for java.time Instant now.

Prototype

public static Instant now() 

Source Link

Document

Obtains the current instant from the system clock.

Usage

From source file:org.sansdemeure.zenindex.main.Main.java

public static void main(String[] args) {

    Instant start = Instant.now();

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ServiceConfig.class);
    ctx.refresh();//w w  w. j  a va2s  .co m

    BatchService batch = (BatchService) ctx.getBean("batchService");
    batch.start(new File(args[0]));

    ctx.close();

    Instant end = Instant.now();
    logger.info("Duration of batch {}", Duration.between(start, end));

}

From source file:DelayedJob.java

public static void main(String[] args) throws InterruptedException {
    BlockingQueue<DelayedJob> queue = new DelayQueue<>();
    Instant now = Instant.now();

    queue.put(new DelayedJob("A", now.plusSeconds(9)));
    queue.put(new DelayedJob("B", now.plusSeconds(3)));
    queue.put(new DelayedJob("C", now.plusSeconds(6)));
    queue.put(new DelayedJob("D", now.plusSeconds(1)));

    while (queue.size() > 0) {
        System.out.println("started...");
        DelayedJob job = queue.take();/*from   w ww. ja  v  a 2s  .  co m*/
        System.out.println("Job: " + job);
    }
    System.out.println("Finished.");
}

From source file:test.SemanticConverter.java

public static void main(String[] args) throws JAXBException {

    SemanticConverter ri = new SemanticConverter();

    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
    RegisterContextRequest rcr = new RegisterContextRequest();
    try {/*from w w  w  . j av a 2  s . c  o  m*/
        rcr = objectMapper.readValue(ri.NGSI_FILE, RegisterContextRequest.class);
    } catch (Exception e) {

    }
    //        RegisterContextRequest rcr = rm.unmarshallRequest(ri.NGSI_FILE);
    rcr.setTimestamp(Instant.now());
    ri.createJenaModel(rcr);

    //        //hMap.put("class", "OnDeviceResource"); 
    ////        hMap.put("class", new String[]{"ResourceService"});
    //        hMap.put("class", new String[]{"VirtualEntity"});
    ////        hMap.put("hasID", new String[]{"Resource_1"});
    //        hMap.put("hasID", new String[]{"VirtualEntity_1"});
    //        hMap.put("hasAttributeType", new String[]{"http://purl.oclc.org/NET/ssnx/qu/quantity#temperature"});     
    ////        hMap.put("isHostedOn", "PloggBoard_49_BA_01_light");
    ////        hMap.put("hasType", "Sensor");
    ////        hMap.put("hasName", "lightsensor49_BA_01");
    ////        hMap.put("isExposedThroughService", "http://www.surrey.ac.uk/ccsr/ontologies/ServiceModel.owl#49_BA_01_light_sensingService");
    ////        hMap.put("hasTag", "light sensor 49,1st,BA,office");
    //        hMap.put("hasLatitude", new String[]{"51.243455"});
    ////        hMap.put("hasGlobalLocation", "http://www.geonames.org/2647793/");
    ////        hMap.put("hasResourceID", "Resource_53_BA_power_sensor");
    ////        hMap.put("hasLocalLocation", "http://www.surrey.ac.uk/ccsr/ontologies/LocationModel.owl#U49");
    //        hMap.put("hasAltitude", new String[]{""});
    //        hMap.put("hasLongitude", new String[]{"-0.588088"});
    ////        hMap.put("hasTimeOffset", "20");
    //
    //        //ri.ONT_URL = "http://www.surrey.ac.uk/ccsr/ontologies/ServiceModel.owl#";
    //        //ri.ONT_URL = "http://www.surrey.ac.uk/ccsr/ontologies/VirtualEntityModel.owl#";
    //        //ri.ONT_FILE = "web/IoTA-Models/VirtualEntityModel.owl";
    //        ri.createJenaModel(hMap);
}

From source file:Main.java

/** Convert a calendar date into a string as specified by http://tools.ietf.org/html/rfc822#section-5.1
 * @param date the calendar instance to convert to a string
 * @param locale the locale to use when outputting strings such as a day of the week, or month of the year.
 * @return a string in the format: "day_abbreviation, day_of_month month_abbreviation year hour:minute:second GMT"
 *//* w  ww .j  a v  a2 s  .  c  o  m*/
// package-private - unused
static final String convertDateToStringRfc822(Calendar date, Locale locale) {
    Date a = Date.from(Instant.now());
    a.toString();
    int day = date.get(Calendar.DAY_OF_MONTH);
    int hour = date.get(Calendar.HOUR_OF_DAY);
    int minute = date.get(Calendar.MINUTE);
    int second = date.get(Calendar.SECOND);
    String str = date.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, locale) + ", "
            + (day < 10 ? "0" + day : day) + " " + date.getDisplayName(Calendar.MONTH, Calendar.SHORT, locale)
            + " " + date.get(Calendar.YEAR) + " " + (hour < 10 ? "0" + hour : hour) + ":"
            + (minute < 10 ? "0" + minute : minute) + ":" + (second < 10 ? "0" + second : second) + " GMT";
    return str;
}

From source file:test.SemanticConverter2.java

public static void main(String[] args) throws JAXBException {

    SemanticConverter2 ri = new SemanticConverter2();

    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
    RegisterContextRequest rcr = new RegisterContextRequest();
    try {//  w  w w  .ja v  a 2 s  .  c  o  m
        rcr = objectMapper.readValue(ri.NGSI_FILE, RegisterContextRequest.class);
    } catch (Exception e) {

    }
    rcr.setTimestamp(Instant.now());
    ri.createJenaModel(rcr);

    //        //hMap.put("class", "OnDeviceResource"); 
    ////        hMap.put("class", new String[]{"ResourceService"});
    //        hMap.put("class", new String[]{"VirtualEntity"});
    ////        hMap.put("hasID", new String[]{"Resource_1"});
    //        hMap.put("hasID", new String[]{"VirtualEntity_1"});
    //        hMap.put("hasAttributeType", new String[]{"http://purl.oclc.org/NET/ssnx/qu/quantity#temperature"});     
    ////        hMap.put("isHostedOn", "PloggBoard_49_BA_01_light");
    ////        hMap.put("hasType", "Sensor");
    ////        hMap.put("hasName", "lightsensor49_BA_01");
    ////        hMap.put("isExposedThroughService", "http://www.surrey.ac.uk/ccsr/ontologies/ServiceModel.owl#49_BA_01_light_sensingService");
    ////        hMap.put("hasTag", "light sensor 49,1st,BA,office");
    //        hMap.put("hasLatitude", new String[]{"51.243455"});
    ////        hMap.put("hasGlobalLocation", "http://www.geonames.org/2647793/");
    ////        hMap.put("hasResourceID", "Resource_53_BA_power_sensor");
    ////        hMap.put("hasLocalLocation", "http://www.surrey.ac.uk/ccsr/ontologies/LocationModel.owl#U49");
    //        hMap.put("hasAltitude", new String[]{""});
    //        hMap.put("hasLongitude", new String[]{"-0.588088"});
    ////        hMap.put("hasTimeOffset", "20");
    //
    //        //ri.ONT_URL = "http://www.surrey.ac.uk/ccsr/ontologies/ServiceModel.owl#";
    //        //ri.ONT_URL = "http://www.surrey.ac.uk/ccsr/ontologies/VirtualEntityModel.owl#";
    //        //ri.ONT_FILE = "web/IoTA-Models/VirtualEntityModel.owl";
    //        ri.createJenaModel(hMap);
}

From source file:DelayedJob.java

@Override
public long getDelay(TimeUnit unit) {
    long delay = MILLIS.between(Instant.now(), scheduledTime);
    long returnValue = unit.convert(delay, MILLISECONDS);
    return returnValue;
}

From source file:test.SemanticConverter3.java

public static void main(String[] args) throws JAXBException {

    SemanticConverter3 ri = new SemanticConverter3();

    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
    RegisterContextRequest rcr = new RegisterContextRequest();
    try {/*ww w  .ja v a2  s. com*/
        rcr = objectMapper.readValue(ri.NGSI_FILE, RegisterContextRequest.class);
    } catch (Exception e) {

    }
    rcr.setTimestamp(Instant.now());
    ri.createJenaModel(rcr);

    //        //hMap.put("class", "OnDeviceResource"); 
    ////        hMap.put("class", new String[]{"ResourceService"});
    //        hMap.put("class", new String[]{"VirtualEntity"});
    ////        hMap.put("hasID", new String[]{"Resource_1"});
    //        hMap.put("hasID", new String[]{"VirtualEntity_1"});
    //        hMap.put("hasAttributeType", new String[]{"http://purl.oclc.org/NET/ssnx/qu/quantity#temperature"});     
    ////        hMap.put("isHostedOn", "PloggBoard_49_BA_01_light");
    ////        hMap.put("hasType", "Sensor");
    ////        hMap.put("hasName", "lightsensor49_BA_01");
    ////        hMap.put("isExposedThroughService", "http://www.surrey.ac.uk/ccsr/ontologies/ServiceModel.owl#49_BA_01_light_sensingService");
    ////        hMap.put("hasTag", "light sensor 49,1st,BA,office");
    //        hMap.put("hasLatitude", new String[]{"51.243455"});
    ////        hMap.put("hasGlobalLocation", "http://www.geonames.org/2647793/");
    ////        hMap.put("hasResourceID", "Resource_53_BA_power_sensor");
    ////        hMap.put("hasLocalLocation", "http://www.surrey.ac.uk/ccsr/ontologies/LocationModel.owl#U49");
    //        hMap.put("hasAltitude", new String[]{""});
    //        hMap.put("hasLongitude", new String[]{"-0.588088"});
    ////        hMap.put("hasTimeOffset", "20");
    //
    //        //ri.ONT_URL = "http://www.surrey.ac.uk/ccsr/ontologies/ServiceModel.owl#";
    //        //ri.ONT_URL = "http://www.surrey.ac.uk/ccsr/ontologies/VirtualEntityModel.owl#";
    //        //ri.ONT_FILE = "web/IoTA-Models/VirtualEntityModel.owl";
    //        ri.createJenaModel(hMap);
}

From source file:fr.ffremont.caching.ExpireCache.java

@GET
@Path("use1month")
public Response use120sec() {
    Date expires = Date.from(Instant.now().plus(30, ChronoUnit.DAYS));

    return Response.ok("ok").expires(expires).build();
}

From source file:dk.dbc.rawrepo.oai.ResumptionToken.java

/**
 * Encode a json object wit a timeout// w ww  .j a v  a  2s  .c om
 *
 * @param obj        json
 * @param validHours timeout
 * @return base64 encoded string
 */
public static String encode(ObjectNode obj, int validHours) {
    if (obj == null) {
        return null;
    }
    long epoch = Instant.now().plus(validHours, ChronoUnit.HOURS).toEpochMilli() / 1000L;
    String format = String.format("%x%s", epoch, obj.toString());
    return PackText.encode(format);
}

From source file:fr.ffremont.caching.ExpireCache.java

@GET
@Path("mix10sec")
public Response mix10sec() {
    Date expires = Date.from(Instant.now().plus(10, ChronoUnit.SECONDS));
    CacheControl cache = new CacheControl();
    cache.setMaxAge(60);//from   w  w w.j  ava2s.  com

    LOG.info("Retour du contenu");
    return Response.ok("En cache pendant 10sec").cacheControl(cache).expires(expires).build();
}