java convert timestamp to date and time

edagarli發表於2014-02-15
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;


public class DateTest {


    public static void main(String[] args) {
        Timestamp timestamp = new Timestamp(System.currentTimeMillis());
        Date date = new Date(timestamp.getTime());
        
        System.out.println(date);
        
        SimpleDateFormat simpleDateFormats = new SimpleDateFormat("MM/dd/yyyy");


        System.out.println(simpleDateFormats.format(date));


        // S is the millisecond
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");


        System.out.println(simpleDateFormat.format(timestamp));
        System.out.println(simpleDateFormat.format(date));
    }
}

相關文章