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:org.apache.hadoop.hive.ql.udf.generic.GenericUDFToUnixTimeStamp.java

protected static void setValueFromTs(LongWritable value, Timestamp timestamp) {
    value.set(timestamp.getTime() / 1000);
}

From source file:Main.java

public static long getTimestamp(String time) {
    time = time + ":00";
    Timestamp ts = new Timestamp(System.currentTimeMillis());
    try {/*from   w  w  w  .j  ava 2 s .co m*/
        ts = Timestamp.valueOf(time);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return ts.getTime();
}

From source file:org.apt.demo.util.Tools.java

public static String convertTimestampToString(Timestamp ts) {
    String s = "";
    try {/*from ww w.j  a  v  a  2 s  . co  m*/
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(ts.getTime());
        int iDate = cal.get(Calendar.DATE);
        int iMonth = cal.get(Calendar.MONTH) + 1;
        int iYear = cal.get(Calendar.YEAR);

        String sDate = (iDate < 10) ? "0" + iDate : "" + iDate;
        String sMonth = (iMonth < 10) ? "0" + iMonth : "" + iMonth;
        s = sDate + "/" + sMonth + "/" + iYear;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    return s;
}

From source file:com.msopentech.odatajclient.engine.data.ODataTimestamp.java

public static ODataTimestamp getInstance(final EdmSimpleType type, final Timestamp timestamp) {
    return new ODataTimestamp(new SimpleDateFormat(type.pattern()), new Date(timestamp.getTime()),
            timestamp.getNanos(), type == EdmSimpleType.DateTimeOffset);
}

From source file:org.finra.herd.core.HerdDateUtils.java

/**
 * Adds a number of days to a timestamp returning a new object. The original {@code Timestamp} is unchanged.
 *
 * @param timestamp the timestamp, not null
 * @param amount the amount to add, may be negative
 *
 * @return the new {@code Timestamp} with the amount added
 *///  w ww  .  j  a  v  a 2s.c  o  m
public static Timestamp addDays(Timestamp timestamp, int amount) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(timestamp.getTime());
    return new Timestamp(addDays(calendar.getTime(), amount).getTime());
}

From source file:org.finra.herd.core.HerdDateUtils.java

/**
 * Adds a number of minutes to a timestamp returning a new object. The original {@code Timestamp} is unchanged.
 *
 * @param timestamp the timestamp, not null
 * @param amount the amount to add, may be negative
 *
 * @return the new {@code Timestamp} with the amount added
 *//*from  w w  w  .j ava 2s.  c om*/
public static Timestamp addMinutes(Timestamp timestamp, int amount) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(timestamp.getTime());
    return new Timestamp(addMinutes(calendar.getTime(), amount).getTime());
}

From source file:com.collective.celos.Util.java

public static ScheduledTime fromTimestamp(Timestamp timestamp) {
    return new ScheduledTime(new DateTime(timestamp.getTime()).withZone(DateTimeZone.UTC));
}

From source file:org.apache.hadoop.chukwa.rest.actions.RestController.java

private static String convertObjectToXml(Object obj) {
    StringBuilder s = new StringBuilder();
    s.append("<item>");
    try {/*  w ww  .j a  v a2s .co  m*/
        Class cls = obj.getClass();

        Field fieldlist[] = cls.getDeclaredFields();
        for (int i = 0; i < fieldlist.length; i++) {
            Field fld = fieldlist[i];
            String fldName = fld.getName();
            String functionName = "get" + fldName.substring(0, 1).toUpperCase() + fldName.substring(1);
            String value = "";
            Object oret = null;
            try {
                @SuppressWarnings("unchecked")
                Method meth = cls.getMethod(functionName);
                if (meth == null) {
                    continue;
                }
                oret = meth.invoke(obj);
            } catch (Exception e) {
                continue;
            }
            if (oret == null) {
                value = "";
            } else if ((oret instanceof Date) || (oret instanceof java.sql.Timestamp)) {

                java.sql.Timestamp d = (java.sql.Timestamp) oret;

                long time = d.getTime();
                String date = DateFormatUtils.format(time, "yyyy-MM-dd HH:mm:ss");
                value = date;
            } else {
                value = oret.toString();
            }

            s.append("<" + fldName + ">" + value + "</" + fldName + ">");
        }
        s.append("\n");
    } catch (Throwable e) {
        System.err.println(e);
    }
    s.append("</item>");
    return s.toString();
}

From source file:Main.java

public static long[] getEntryExit(Double id, Calendar date, Connection con, PreparedStatement stmt)
        throws Exception {
    stmt.setDate(1, new java.sql.Date(date.getTimeInMillis()));
    // stmt.setDate(2, new java.sql.Date(date.getTimeInMillis()+1000000));
    stmt.execute();/* w  w w. j  ava  2 s. c om*/
    ResultSet rs = stmt.getResultSet();
    if (rs != null) {

        if (rs.next()) {
            Timestamp d1 = rs.getTimestamp(1);
            Timestamp d2 = rs.getTimestamp(2);
            if (d1 != null && d2 != null) {
                System.out.println(id + ":" + new SimpleDateFormat("dd/MM/yyyy").format(date.getTime()) + ":"
                        + d1.toString());
                long[] res = new long[] { d1.getTime(), d2.getTime() };
                return res;
            }
        }
        rs.close();
    }
    return null;
}

From source file:com.wolvencraft.yasp.util.Util.java

/**
 * Returns the current time in seconds.// w  w  w. ja va2  s.c  om
 *
 * @return Current time
 */
public static long getTimestamp() {
    Timestamp timestamp = new Timestamp(new java.util.Date().getTime());
    return timestamp.getTime() / 1000;
}