Example usage for java.sql Timestamp getTime

List of usage examples for java.sql Timestamp getTime

Introduction

In this page you can find the example usage for java.sql Timestamp getTime.

Prototype

public long getTime() 

Source Link

Document

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Timestamp object.

Usage

From source file:uk.org.funcube.fcdw.server.extract.csv.WodCsvExtractor.java

/**
 * @param wod24/*from  w  ww.j  av  a  2 s  .c o  m*/
 * @param fileLocation
 */
private void writeFile(List<WholeOrbitDataEntity> wod, File fileLocation) {
    try {
        // use FileWriter constructor that specifies open for appending
        CsvWriter csvOutput = new CsvWriter(new FileWriter(fileLocation, true), ',');

        // write out the headers
        csvOutput.write("Satellite Date/Time UTC");
        csvOutput.write("Black Chassis deg. C");
        csvOutput.write("Silver Chassis deg. C");
        csvOutput.write("Black Panel deg. C");
        csvOutput.write("Silver Panel deg. C");
        csvOutput.write("Solar Panel +X deg. C");
        csvOutput.write("Solar Panel -X deg. C");
        csvOutput.write("Solar Panel +Y deg. C");
        csvOutput.write("Solar Panel -Y deg. C");
        csvOutput.write("Solar Panel X mV");
        csvOutput.write("Solar Panel Y mV");
        csvOutput.write("Solar Panel Z mV");
        csvOutput.write("Tot. Photo Curr. mA ");
        csvOutput.write("Battery mV");
        csvOutput.write("Tot. System Curr. mA");
        csvOutput.endRecord();

        long tsLong = 0;
        String c1 = "";
        String c2 = "";
        String c3 = "";
        String c4 = "";
        String c5 = "";
        String c6 = "";
        String c7 = "";
        String c8 = "";
        String c9 = "";
        String c10 = "";
        String c11 = "";
        String c12 = "";
        String c13 = "";
        String c14 = "";

        for (WholeOrbitDataEntity entity : wod) {

            Timestamp satelliteTime = new Timestamp(entity.getCreatedDate().getTime());

            if (tsLong == 0) {
                tsLong = satelliteTime.getTime();
                c1 = scale(entity.getC1(), -0.024, 75.244);
                c2 = scale(entity.getC2(), -0.024, 74.750);
                c3 = scale(entity.getC3(), -0.024, 75.039);
                c4 = scale(entity.getC4(), -0.024, 75.987);
                c5 = scale(entity.getC5(), -0.2073, 158.239);
                c6 = scale(entity.getC6(), -0.2083, 159.227);
                c7 = scale(entity.getC7(), -0.2076, 158.656);
                c8 = scale(entity.getC8(), -0.2087, 159.045);
                c9 = String.format("%4d", entity.getC9());
                c10 = String.format("%4d", entity.getC10());
                c11 = String.format("%4d", entity.getC11());
                c12 = String.format("%4d", entity.getC12());
                c13 = String.format("%4d", entity.getC13());
                c14 = String.format("%4d", entity.getC14());

                writeRecord(csvOutput, satelliteTime, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13,
                        c14);
            } else {

                final long timeDiff = satelliteTime.getTime() - tsLong;
                if (timeDiff > 60000) {
                    // fill in the gaps
                    long gaps = (timeDiff / 60000);
                    for (long i = 1; i < gaps; i++) {
                        Timestamp intervalTime = new Timestamp(tsLong + (60000 * i));
                        writeRecord(csvOutput, intervalTime, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12,
                                c13, c14);
                    }
                }

                c1 = scale(entity.getC1(), -0.024, 75.244);
                c2 = scale(entity.getC2(), -0.024, 74.750);
                c3 = scale(entity.getC3(), -0.024, 75.039);
                c4 = scale(entity.getC4(), -0.024, 75.987);
                c5 = scale(entity.getC5(), -0.2073, 158.239);
                c6 = scale(entity.getC6(), -0.2083, 159.227);
                c7 = scale(entity.getC7(), -0.2076, 158.656);
                c8 = scale(entity.getC8(), -0.2087, 159.045);
                c9 = String.format("%4d", entity.getC9());
                c10 = String.format("%4d", entity.getC10());
                c11 = String.format("%4d", entity.getC11());
                c12 = String.format("%4d", entity.getC12());
                c13 = String.format("%4d", entity.getC13());
                c14 = String.format("%4d", entity.getC14());

                writeRecord(csvOutput, satelliteTime, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13,
                        c14);

                tsLong = satelliteTime.getTime();
            }
        }

        csvOutput.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:cn.mljia.common.notify.utils.DateUtils.java

/**
 * ?//  w ww. j  a  va 2s  .  c o  m
 * 
 * @return t1t2t2  t1??
 */
public static long daysBetween(java.sql.Timestamp t1, java.sql.Timestamp t2) {
    return (t2.getTime() - t1.getTime()) / DAY_MILLI;
}

From source file:jp.co.ctc_g.jfw.core.util.Dates.java

/**
 * ??????????.<br>/*from ww w .  ja v a  2s.c om*/
 * ??{#difference({@link java.sql.Timestamp java.sql.Timestamp},
 * {@link java.sql.Timestamp java.sql.Timestamp}) difference(Date, Date)}
 * ???????????.
 * @param date ?
 * @return ???
 */
public static long difference(Timestamp date) {

    return Dates.getDate().getTime() - date.getTime();
}

From source file:bboss.org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader.java

/**
 * Fetches the last modification time of the resource
 *
 * @param resource Resource object we are finding timestamp of
 * @param operation string for logging, indicating caller's intention
 *
 * @return timestamp as long//from  w w  w  . ja  va  2  s  . c o m
 */
private long readLastModified(final Resource resource, final String operation) {
    long timeStamp = 0;

    /* get the template name from the resource */
    String name = resource.getName();
    if (name == null || name.length() == 0) {
        String msg = "DataSourceResourceLoader: Template name was empty or null";
        log.error(msg);
        throw new NullPointerException(msg);
    } else {
        Connection conn = null;
        ResultSet rs = null;
        PreparedStatement ps = null;

        try {
            conn = openDbConnection();
            ps = getStatement(conn, timestampColumn, name);
            rs = ps.executeQuery();

            if (rs.next()) {
                Timestamp ts = rs.getTimestamp(timestampColumn);
                timeStamp = ts != null ? ts.getTime() : 0;
            } else {
                String msg = "DataSourceResourceLoader: could not find resource " + name + " while "
                        + operation;
                log.error(msg);
                throw new ResourceNotFoundException(msg);
            }
        } catch (SQLException sqle) {
            String msg = "DataSourceResourceLoader: database problem while " + operation + " of '" + name
                    + "': ";

            log.error(msg, sqle);
            throw ExceptionUtils.createRuntimeException(msg, sqle);
        } catch (NamingException ne) {
            String msg = "DataSourceResourceLoader: database problem while " + operation + " of '" + name
                    + "': ";

            log.error(msg, ne);
            throw ExceptionUtils.createRuntimeException(msg, ne);
        } finally {
            closeResultSet(rs);
            closeStatement(ps);
            closeDbConnection(conn);
        }
    }
    return timeStamp;
}

From source file:edu.utah.further.mdr.data.common.domain.asset.AbstractVersionEntity.java

/**
 * @param other// w  w w. j  a  v  a  2 s  .  c o  m
 * @return
 * @see edu.utah.further.mdr.api.domain.asset.Version#copyFrom(edu.utah.further.mdr.api.domain.asset.Version)
 */
@Override
public Version copyFrom(final Version other) {
    if (other == null) {
        return this;
    }

    // Identifier is not copied

    // Deep-copy fields
    setAsset(other.getAsset());
    this.status = (LookupValueEntity) other.getStatus();
    this.version = other.getVersion();
    setPropertiesXml(other.getPropertiesXml());
    this.updatedByUserId = other.getUpdatedByUserId();
    final Timestamp otherUpdatedDate = other.getUpdatedDate();
    if (otherUpdatedDate != null) {
        this.updatedDate = new Timestamp(otherUpdatedDate.getTime());
    }
    this.updateDescription = other.getUpdateDescription();

    // Deep-copy collection references but soft-copy their elements unless it's easy
    // to deep-copy them too
    // this.resourceSet = newSet();
    // for (final Resource resource : other.getResourceSet())
    // {
    // addResource(new ResourceEntity().copyFrom(resource));
    // }

    // Deep-copy collection references but soft-copy their elements

    return this;
}

From source file:org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader.java

/**
 * Fetches the last modification time of the resource
 *
 * @param resource Resource object we are finding timestamp of
 * @param operation string for logging, indicating caller's intention
 *
 * @return timestamp as long/*from  w w  w.  j  av a 2s  .c om*/
 */
private long readLastModified(final Resource resource, final String operation) {
    long timeStamp = 0;

    /* get the template name from the resource */
    String name = resource.getName();
    if (name == null || name.length() == 0) {
        String msg = "DataSourceResourceLoader: Template name was empty or null";
        Logger.error(this, msg);
        throw new NullPointerException(msg);
    } else {
        Connection conn = null;
        ResultSet rs = null;
        PreparedStatement ps = null;

        try {
            conn = openDbConnection();
            ps = getStatement(conn, timestampColumn, name);
            rs = ps.executeQuery();

            if (rs.next()) {
                Timestamp ts = rs.getTimestamp(timestampColumn);
                timeStamp = ts != null ? ts.getTime() : 0;
            } else {
                String msg = "DataSourceResourceLoader: could not find resource " + name + " while "
                        + operation;
                Logger.error(this, msg);
                throw new ResourceNotFoundException(msg);
            }
        } catch (SQLException sqle) {
            String msg = "DataSourceResourceLoader: database problem while " + operation + " of '" + name
                    + "': ";

            Logger.error(this, msg, sqle);
            throw ExceptionUtils.createRuntimeException(msg, sqle);
        } catch (NamingException ne) {
            String msg = "DataSourceResourceLoader: database problem while " + operation + " of '" + name
                    + "': ";

            Logger.error(this, msg, ne);
            throw ExceptionUtils.createRuntimeException(msg, ne);
        } finally {
            closeResultSet(rs);
            closeStatement(ps);
            closeDbConnection(conn);
        }
    }
    return timeStamp;
}

From source file:de.micromata.genome.logging.spi.ifiles.IndexHeader.java

/**
 * /*from w ww.j  a  va 2s  . c o  m*/
 * @param start when to start
 * @param end when to end
 * @param mem the buffer in the memory
 * @param filesize the size of the file
 * @return startoffset, endidx
 */
public List<Pair<Integer, Integer>> getCandiates(Timestamp start, Timestamp end, MappedByteBuffer mem,
        int filesize) {
    List<Pair<Integer, Integer>> ret = new ArrayList<>();

    int pos = filesize - ROW_LENGTH;
    while (pos >= 0) {
        long logt = mem.getLong(pos);
        if (start != null && start.getTime() > logt) {
            continue;
        }
        if (end != null && end.getTime() < logt) {
            break;
        }
        int offset = mem.getInt(pos + Long.BYTES);
        int endOfset = -1;
        if (pos + ROW_LENGTH + Integer.BYTES < filesize) {
            endOfset = mem.getInt(pos + Long.BYTES + ROW_LENGTH);
        }
        if (offset == endOfset) {
            // oops
            System.out.println("Oops");
        }
        ret.add(Pair.make(offset, endOfset));
        pos -= ROW_LENGTH;
    }
    return ret;
}

From source file:com.intellectualcrafters.plot.commands.DebugExec.java

@Override
public boolean execute(final PlotPlayer player, final String... args) {
    final List<String> allowed_params = Arrays.asList("analyze", "reset-modified", "stop-expire",
            "start-expire", "show-expired", "update-expired", "seen", "trim-check");
    if (args.length > 0) {
        final String arg = args[0].toLowerCase();
        switch (arg) {
        case "analyze": {
            final Plot plot = MainUtil.getPlot(player.getLocation());
            HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>() {
                @Override/*from  w  w  w  .  j  a  v a2 s .c om*/
                public void run() {
                    List<Double> result = new ArrayList<>();
                    result.add(Math.round(value.air * 100) / 100d);
                    result.add(Math.round(value.changes * 100) / 100d);
                    result.add(Math.round(value.complexity * 100) / 100d);
                    result.add(Math.round(value.data * 100) / 100d);
                    result.add(Math.round(value.faces * 100) / 100d);
                    result.add(Math.round(value.air * 100) / 100d);
                    result.add(Math.round(value.variety * 100) / 100d);
                    Flag flag = new Flag(FlagManager.getFlag("analysis"), result);
                    FlagManager.addPlotFlag(plot, flag);
                }
            });
            return true;
        }
        case "stop-expire": {
            if (ExpireManager.task != -1) {
                Bukkit.getScheduler().cancelTask(ExpireManager.task);
            } else {
                return MainUtil.sendMessage(player, "Task already halted");
            }
            ExpireManager.task = -1;
            return MainUtil.sendMessage(player, "Cancelled task.");
        }
        case "remove-flag": {
            if (args.length != 2) {
                MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec reset-flat <flag>");
                return false;
            }
            String flag = args[1];
            for (Plot plot : PS.get().getPlots()) {
                if (FlagManager.getPlotFlag(plot, flag) != null) {
                    FlagManager.removePlotFlag(plot, flag);
                }
            }
            return MainUtil.sendMessage(player, "Cleared flag: " + flag);
        }
        case "start-rgar": {
            if (args.length != 2) {
                PS.log("&cInvalid syntax: /plot debugexec start-rgar <world>");
                return false;
            }
            boolean result;
            if (!PS.get().isPlotWorld(args[1])) {
                MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD, args[1]);
                return false;
            }
            if (BukkitHybridUtils.regions != null) {
                result = ((BukkitHybridUtils) (HybridUtils.manager)).scheduleRoadUpdate(args[1],
                        BukkitHybridUtils.regions, 0);
            } else {
                result = HybridUtils.manager.scheduleRoadUpdate(args[1], 0);
            }
            if (!result) {
                PS.log("&cCannot schedule mass schematic update! (Is one already in progress?)");
                return false;
            }
            return true;
        }
        case "stop-rgar": {
            if (((BukkitHybridUtils) (HybridUtils.manager)).task == 0) {
                PS.log("&cTASK NOT RUNNING!");
                return false;
            }
            ((BukkitHybridUtils) (HybridUtils.manager)).task = 0;
            Bukkit.getScheduler().cancelTask(((BukkitHybridUtils) (HybridUtils.manager)).task);
            PS.log("&cCancelling task...");
            while (BukkitHybridUtils.chunks.size() > 0) {
                ChunkLoc chunk = BukkitHybridUtils.chunks.get(0);
                BukkitHybridUtils.chunks.remove(0);
                HybridUtils.manager.regenerateRoad(BukkitHybridUtils.world, chunk, 0);
                ChunkManager.manager.unloadChunk(BukkitHybridUtils.world, chunk);
            }
            PS.log("&cCancelled!");
            return true;
        }
        case "start-expire": {
            if (ExpireManager.task == -1) {
                ExpireManager.runTask();
            } else {
                return MainUtil.sendMessage(player, "Plot expiry task already started");
            }
            return MainUtil.sendMessage(player, "Started plot expiry task");
        }
        case "update-expired": {
            if (args.length > 1) {
                final String world = args[1];
                if (!BlockManager.manager.isWorld(world)) {
                    return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
                }
                MainUtil.sendMessage(player, "Updating expired plot list");
                ExpireManager.updateExpired(args[1]);
                return true;
            }
            return MainUtil.sendMessage(player, "Use /plot debugexec update-expired <world>");
        }
        case "show-expired": {
            if (args.length > 1) {
                final String world = args[1];
                if (!BlockManager.manager.isWorld(world)) {
                    return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
                }
                if (!ExpireManager.expiredPlots.containsKey(args[1])) {
                    return MainUtil.sendMessage(player, "No task for world: " + args[1]);
                }
                MainUtil.sendMessage(player,
                        "Expired plots (" + ExpireManager.expiredPlots.get(args[1]).size() + "):");
                for (final Plot plot : ExpireManager.expiredPlots.get(args[1])) {
                    MainUtil.sendMessage(player, " - " + plot.world + ";" + plot.id.x + ";" + plot.id.y + ";"
                            + UUIDHandler.getName(plot.owner) + " : " + ExpireManager.dates.get(plot.owner));
                }
                return true;
            }
            return MainUtil.sendMessage(player, "Use /plot debugexec show-expired <world>");
        }
        case "seen": {
            if (args.length != 2) {
                return MainUtil.sendMessage(player, "Use /plot debugexec seen <player>");
            }
            final UUID uuid = UUIDHandler.getUUID(args[1]);
            if (uuid == null) {
                return MainUtil.sendMessage(player, "player not found: " + args[1]);
            }
            final OfflinePlotPlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
            if ((op == null) || (op.getLastPlayed() == 0)) {
                return MainUtil.sendMessage(player, "player hasn't connected before: " + args[1]);
            }
            final Timestamp stamp = new Timestamp(op.getLastPlayed());
            final Date date = new Date(stamp.getTime());
            MainUtil.sendMessage(player, "PLAYER: " + args[1]);
            MainUtil.sendMessage(player, "UUID: " + uuid);
            MainUtil.sendMessage(player, "Object: " + date.toGMTString());
            MainUtil.sendMessage(player, "GMT: " + date.toGMTString());
            MainUtil.sendMessage(player, "Local: " + date.toLocaleString());
            return true;
        }
        case "trim-check": {
            if (args.length != 2) {
                MainUtil.sendMessage(player, "Use /plot debugexec trim-check <world>");
                MainUtil.sendMessage(player, "&7 - Generates a list of regions to trim");
                return MainUtil.sendMessage(player, "&7 - Run after plot expiry has run");
            }
            final String world = args[1];
            if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(args[1])) {
                return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
            }
            final ArrayList<ChunkLoc> empty = new ArrayList<>();
            final boolean result = Trim.getTrimRegions(empty, world, new Runnable() {
                @Override
                public void run() {
                    Trim.sendMessage("Processing is complete! Here's how many chunks would be deleted:");
                    Trim.sendMessage(" - MCA #: " + empty.size());
                    Trim.sendMessage(" - CHUNKS: " + (empty.size() * 1024) + " (max)");
                    Trim.sendMessage("Exporting log for manual approval...");
                    final File file = new File(PS.get().IMP.getDirectory() + File.separator + "trim.txt");
                    PrintWriter writer;
                    try {
                        writer = new PrintWriter(file);
                        for (final ChunkLoc loc : empty) {
                            writer.println(world + "/region/r." + loc.x + "." + loc.z + ".mca");
                        }
                        writer.close();
                        Trim.sendMessage("File saved to 'plugins/PlotSquared/trim.txt'");
                    } catch (final FileNotFoundException e) {
                        e.printStackTrace();
                        Trim.sendMessage("File failed to save! :(");
                    }
                    Trim.sendMessage("How to get the chunk coords from a region file:");
                    Trim.sendMessage(
                            " - Locate the x,z values for the region file (the two numbers which are separated by a dot)");
                    Trim.sendMessage(" - Multiply each number by 32; this gives you the starting position");
                    Trim.sendMessage(" - Add 31 to each number to get the end position");
                }
            });
            if (!result) {
                MainUtil.sendMessage(player, "Trim task already started!");
            }
            return result;
        }
        }
    }
    MainUtil.sendMessage(player,
            "Possible sub commands: /plot debugexec <" + StringUtils.join(allowed_params, "|") + ">");
    return true;
}

From source file:de.kp.ames.web.core.domain.model.JsonRegistryObject.java

/**
 * Convert registry object into JSON object
 * //w  w w.ja  v  a  2  s  .c o m
 * @param ro
 * @param locale
 * @return
 * @throws JAXRException 
 * @throws JSONException 
 * @throws Exception
 */
public void set(RegistryObjectImpl ro, Locale locale) throws JSONException, JAXRException {

    /*
     * Convert identifier       
     */
    put(JaxrConstants.RIM_ID, ro.getId());
    put(JaxrConstants.RIM_LID, ro.getLid());

    /* 
     * Convert name
     */
    String name = jaxrBase.getName(ro, locale);

    /*
     * If no matching locale string exists, get the closest match
     */
    name = (name == "") ? ro.getDisplayName() : name;

    put(JaxrConstants.RIM_NAME, name);

    /*
     * Convert description
     */
    String description = jaxrBase.getDescription(ro, locale);
    description = (description == "") ? ((InternationalStringImpl) ro.getDescription()).getClosestValue()
            : description;

    put(JaxrConstants.RIM_DESC, description);

    /*
     * Convert object type
     */
    String objectType = ro.getObjectType().getKey().getId();
    put(JaxrConstants.RIM_TYPE, objectType);

    /*
     * Convert home
     */
    String home = jaxrBase.getHome(ro);
    put(JaxrConstants.RIM_HOME, home);

    /*
     * Convert status
     */
    String status = jaxrBase.getStatus(ro);
    put(JaxrConstants.RIM_STATUS, status);

    /* 
     * Convert version               
     */
    String version = ro.getVersionName();
    put(JaxrConstants.RIM_VERSION, version);

    /*
     * Convert author
     */
    String author = jaxrBase.getAuthor(ro);
    put(JaxrConstants.RIM_AUTHOR, author);

    /*
     * Convert owner
     */
    String owner = jaxrBase.getOwner(ro);
    put(JaxrConstants.RIM_OWNER, owner);

    /*
     * Convert timestamp & events
     */
    AuditableEventImpl auditableEvent = jaxrBase.getLastEvent(ro);

    Timestamp lastModified = (auditableEvent == null) ? null : auditableEvent.getTimestamp();
    if (lastModified != null) {

        /*
         * Timestamp
         */
        long milliseconds = lastModified.getTime() + (lastModified.getNanos() / 1000000);
        put(JaxrConstants.RIM_TIMESTAMP, new Date(milliseconds).toString());

        /*
         * Event
         */
        String eventType = jaxrBase.getLastEventType(ro);
        put(JaxrConstants.RIM_EVENT, eventType);

    }

    /*
     * Classifications
     */
    JSONObject jClases = getClassifications(ro);
    put(JaxrConstants.RIM_CLAS, jClases.toString());

    /*
     * Slots
     */
    JSONObject jSlot = getSlots(ro);
    put(JaxrConstants.RIM_SLOT, jSlot.toString());

}

From source file:org.elasticsearch.querydoge.QueryDogeTest.java

/**
 * @return/* w ww . j  a va2 s.  c  om*/
 */
private long generateRandomTimeStamp() {
    long offset = Timestamp.valueOf("2013-01-01 00:00:00").getTime();
    long end = Timestamp.valueOf("2014-01-01 00:00:00").getTime();
    long diff = end - offset + 1;
    Timestamp rand = new Timestamp(offset + (long) (Math.random() * diff));
    return rand.getTime();
}