Java Timestamp Convert To ConvertTimestamp(long sec)

Here you can find the source of ConvertTimestamp(long sec)

Description

Convert Timestamp

License

Open Source License

Declaration

public static Timestamp ConvertTimestamp(long sec) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    public static Timestamp ConvertTimestamp(long sec) {
        long unixSeconds = sec / 1000;
        Date date = new Date(unixSeconds * 1000L); // *1000 is to convert seconds to milliseconds
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // the format of your date
        sdf.setTimeZone(TimeZone.getTimeZone("GMT+8")); // give a timezone reference for formating (see comment at the bottom
        String dt = sdf.format(date);
        return Timestamp.valueOf(dt);
    }/*from w  w w . j a  v a  2  s . co  m*/
}

Related

  1. convertDate(Timestamp time)
  2. convertTimestamp(Timestamp timestamp)
  3. convertTimestampToDate(Timestamp timestamp)
  4. convertTimestampToDDMMMMYYYY(Timestamp dateTime)
  5. convertTimestampToString(Timestamp dateTime, String dateFormat)