Example usage for java.sql Timestamp Timestamp

List of usage examples for java.sql Timestamp Timestamp

Introduction

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

Prototype

public Timestamp(long time) 

Source Link

Document

Constructs a Timestamp object using a milliseconds time value.

Usage

From source file:Main.java

public static String getSysDateTimeMillis() {
    String str = new Timestamp(System.currentTimeMillis()).toString();
    if (str.length() >= 23) {
        return str.substring(0, 23);
    } else {//from w w w  .ja  va 2s. c om
        StringBuilder sb = new StringBuilder();
        sb.append(str);
        for (int i = 0; i < 23 - str.length(); i++) {
            sb.append("0");
        }
        return sb.toString();
    }
}

From source file:Main.java

public static String formatDateStr(String dateStr, String format) {
    Timestamp ts = new Timestamp(Long.valueOf(dateStr));
    return new SimpleDateFormat(format).format(ts);
}

From source file:Main.java

public static java.sql.Timestamp convertToSqlTimestamp(Date date) {
    return new Timestamp(date.getTime());
}

From source file:Main.java

public static Timestamp toTimestamp(ZonedDateTime dateTime) {
    return new Timestamp(dateTime.toInstant().getEpochSecond() * 1000L);
}

From source file:Main.java

public static String convertmstodate(long timeStamp) {
    String result;/*w  w  w  .j a  v  a  2s .c o m*/
    Timestamp timestamp = new Timestamp(timeStamp);
    Date date = new Date(timestamp.getTime());

    // S is the millisecond
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
    result = simpleDateFormat.format(timestamp);
    // System.out.println(simpleDateFormat.format(timestamp));
    // System.out.println(simpleDateFormat.format(date));

    return result;
}

From source file:Main.java

public static String getDateTimeTextFromTimestamp(Long timestamp) {
    Timestamp stamp = new Timestamp(timestamp);
    Date date = new Date(stamp.getTime());
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat s = new SimpleDateFormat("dd MMM yyyy HH:mm");
    s.setTimeZone(cal.getTimeZone());/*from w w w  . j a  v  a  2 s.c o  m*/
    return s.format(date);
}

From source file:Main.java

public static String getFileName() {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss_SS");
    String fileName = format.format(new Timestamp(System.currentTimeMillis()));
    return fileName;
}

From source file:Main.java

public static Timestamp getCurrentDate() {

    Calendar c = Calendar.getInstance();
    c.set(c.get(1), c.get(2), c.get(5), 0, 0, 0);
    Timestamp t = new Timestamp(c.getTime().getTime());
    t.setNanos(0);//from w  w  w . ja va2  s  .  c  om
    return t;
}

From source file:Main.java

public static String formatTime(long timestamp) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    try {//from  ww  w . j a  v a  2  s.c o  m
        return sdf.format(new Timestamp(timestamp));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return String.valueOf(timestamp);
}

From source file:Main.java

public static String timeStampToDate(String time, String format) {
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    Timestamp ts = new Timestamp(Long.valueOf(time) * 1000);
    String date = sdf.format(ts);
    return date;//from   www.j  a  v a2s  .  c o  m
}