Example usage for java.time Instant toEpochMilli

List of usage examples for java.time Instant toEpochMilli

Introduction

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

Prototype

public long toEpochMilli() 

Source Link

Document

Converts this instant to the number of milliseconds from the epoch of 1970-01-01T00:00:00Z.

Usage

From source file:Main.java

public static void main(String[] args) {
    Instant instant = Instant.parse("2014-12-03T10:15:30.00Z");
    System.out.println(instant.toEpochMilli());

}

From source file:Main.java

public static void main(String[] args) {

    // same time in millis
    Instant now = Instant.ofEpochMilli(1262347200000l);

    long toUnixTimestamp = now.toEpochMilli();

    System.out.println(toUnixTimestamp);
}

From source file:Main.java

private static long getMillis(String strDate, DateTimeFormatter formatter, ZoneId zone) {
    LocalDateTime localDateTime = LocalDateTime.parse(strDate, formatter);
    ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, zone);
    Instant instant = zonedDateTime.toInstant();
    long milli = instant.toEpochMilli();
    return milli;
}

From source file:edu.usu.sdl.openstorefront.common.util.TimeUtil.java

/**
 * Get the start of the day passed in//from www .  j ava 2s .  c  om
 *
 * @param date
 * @return beginning of day or null if date was null
 */
public static Date beginningOfDay(Date date) {
    if (date != null) {
        Instant instant = Instant.ofEpochMilli(date.getTime()).truncatedTo(ChronoUnit.DAYS);
        return new Date(instant.toEpochMilli());
    }
    return date;
}

From source file:com.teradata.benchto.service.BenchmarkControllerTest.java

private static String toJsonRepresentation(Instant instant) {
    return format("%d.%03d", instant.getEpochSecond(), instant.toEpochMilli() % 1000);
}

From source file:com.sonicle.webtop.mail.bol.model.ImapQuery.java

private static Date parseDate(String value, DateTimeZone timezone) {
    String date = StringUtils.replace(value, "/", "-");
    Instant instant = DateTimeUtils.toInstant(DateTimeUtils.parseLocalDate(date),
            DateTimeUtils.toZoneId(timezone));
    return new Date(instant.toEpochMilli());
}

From source file:com.hurence.logisland.connect.opc.CommonUtils.java

/**
 * Maps an opc data to a kafka connect object.
 *
 * @param opcData         the read data/*from ww w.  ja  v  a  2 s.  c  o m*/
 * @param timestamp       the data timestamp
 * @param meta            the tag information
 * @param schema
 * @param valueSchema
 * @param additionalProps
 * @return
 */
public static Struct mapToConnectObject(OpcData opcData, Instant timestamp, TagInfo meta, Schema schema,
        SchemaAndValue valueSchema, Map<String, Object> additionalProps) {
    Struct value = new Struct(schema).put(OpcRecordFields.SAMPLED_TIMESTAMP, timestamp.toEpochMilli())
            .put(OpcRecordFields.SOURCE_TIMESTAMP, opcData.getTimestamp().toEpochMilli())
            .put(OpcRecordFields.TAG_ID, opcData.getTag())
            .put(OpcRecordFields.QUALITY, opcData.getQuality().name())
            .put(OpcRecordFields.SAMPLING_RATE, meta.getSamplingInterval().toMillis());
    additionalProps.forEach(value::put);

    if (valueSchema.value() != null) {
        value = value.put(OpcRecordFields.VALUE, valueSchema.value());
    }
    if (opcData.getOperationStatus().getLevel().compareTo(OperationStatus.Level.INFO) > 0) {
        value.put(OpcRecordFields.ERROR_CODE, opcData.getOperationStatus().getCode());
        if (opcData.getOperationStatus().getMessageDetail().isPresent()) {
            value.put(OpcRecordFields.ERROR_REASON, opcData.getOperationStatus().getMessageDetail().get());
        }
    }
    return value;
}

From source file:org.ulyssis.ipp.publisher.Score.java

public Score(Snapshot snapshot, boolean publicScore) {
    Config config = Config.getCurrentConfig();
    Instant now = Instant.now();
    this.time = now.toEpochMilli();
    this.lap = config.getTrackLength();
    this.update = snapshot.getUpdateFrequency();
    this.teams = new TreeSet<>();
    this.status = snapshot.getStatus();
    this.message = snapshot.getStatusMessage();
    TeamStates teamStates = publicScore ? snapshot.getPublicTeamStates() : snapshot.getTeamStates();
    for (org.ulyssis.ipp.config.Team team : config.getTeams()) {
        Optional<TeamState> teamState = teamStates.getStateForTeam(team.getTeamNb());
        if (teamState.isPresent()) {
            TeamState t = teamState.get();
            double speed = t.getPredictedSpeed();
            if (Double.isNaN(speed)) {
                teams.add(new Team(lap, team.getTeamNb(), team.getName(), 0, 0, 0, 0));
            } else {
                TagSeenEvent lastEvent = t.getLastTagSeenEvent().get();
                Instant lastTime = t.getLastTagSeenEvent().get().getTime();
                double elapsedSeconds = Duration.between(lastTime, now).toMillis() / 1000D;
                double previousReaderPosition = config.getReader(lastEvent.getReaderId()).getPosition();
                double nonLimitedPosition = previousReaderPosition + elapsedSeconds * speed;
                double position = nonLimitedPosition;
                if (position > config.getTrackLength())
                    position = config.getTrackLength();
                teams.add(new Team(lap, team.getTeamNb(), team.getName(), t.getNbLaps(),
                        position / config.getTrackLength(), nonLimitedPosition / config.getTrackLength(),
                        speed));/*w  w  w.java  2 s.  c om*/
            }
        } else {
            teams.add(new Team(lap, team.getTeamNb(), team.getName(), 0, 0, 0, 0));
        }
    }
}

From source file:edu.usu.sdl.openstorefront.report.SubmissionsReport.java

private void updateReportTimeRange() {
    if (report.getReportOption().getPreviousDays() != null) {
        Instant instant = Instant.now();
        instant = instant.minus(1, ChronoUnit.DAYS);
        report.getReportOption().setStartDts(TimeUtil.beginningOfDay(new Date(instant.toEpochMilli())));
        report.getReportOption().setEndDts(TimeUtil.endOfDay(new Date(instant.toEpochMilli())));
    }/*from   w w  w.j av a 2s.co m*/
    if (report.getReportOption().getStartDts() == null) {
        report.getReportOption().setStartDts(TimeUtil.beginningOfDay(new Date()));
    }
    if (report.getReportOption().getEndDts() == null) {
        report.getReportOption().setEndDts(TimeUtil.endOfDay(new Date()));
    }
}

From source file:cn.edu.zjnu.acm.judge.user.ResetPasswordController.java

@SuppressWarnings("NestedAssignment")
private boolean checkVcode(HttpServletRequest request) {
    String uid = request.getParameter("u");
    String vcode = request.getParameter("vc");
    User user = null;/*from ww  w  .jav a  2  s.c o m*/
    if (uid != null) {
        user = userMapper.findOne(uid);
    }
    String code;
    Instant expire;
    return user != null && (code = user.getVcode()) != null && code.equals(vcode)
            && ((expire = user.getExpireTime()) == null || expire.toEpochMilli() > System.currentTimeMillis());
}