Java Timestamp Format timestamp2String(long source, DateFormat format)

Here you can find the source of timestamp2String(long source, DateFormat format)

Description

timestamp String

License

Apache License

Declaration

public static String timestamp2String(long source, DateFormat format) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static String timestamp2String(long source, DateFormat format) {
        return date2String(timestamp2Date(source), format);
    }//from  w w  w.j a va  2 s .  c  o  m

    public static String timestamp2String(long source, String formatString) {
        return date2String(timestamp2Date(source), new SimpleDateFormat(formatString));
    }

    public static String date2String(Date source, String formatString) {
        return date2String(source, new SimpleDateFormat(formatString));
    }

    public static String date2String(Date source, DateFormat format) {
        try {
            return format.format(source);
        } catch (Exception e) {
            return "";
        }
    }

    public static Date timestamp2Date(long source) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(source);
        return calendar.getTime();
    }
}

Related

  1. stringConvertToTimestamp(String value, String format)
  2. TimeStamp2Date(long timestampString, String formats)
  3. timeStamp2Date(String seconds, String format)
  4. Timestamp2DDMMYYYY(java.sql.Timestamp ts)
  5. Timestamp2HHMMSS(java.sql.Timestamp ts, int iStyle)
  6. Timestamp2UTC(Timestamp mytime)
  7. timestampConvertToString(int timeStamp, String format)
  8. timeStampForFileName(final String simpleDateFormat)
  9. timestampFormat(Date date)