Java Date to Time getTimeStamp(long timeMilis, boolean time, boolean date)

Here you can find the source of getTimeStamp(long timeMilis, boolean time, boolean date)

Description

get Time Stamp

License

Open Source License

Declaration

public static String getTimeStamp(long timeMilis, boolean time, boolean date) 

Method Source Code

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

import java.util.Calendar;

public class Main {
    private static Calendar cal = Calendar.getInstance();

    public static String getTimeStamp(long timeMilis, boolean time, boolean date) {
        return getTimeStamp(new StringBuilder(), timeMilis, time, date).toString();
    }/*from   w ww . ja va  2 s . com*/

    public static StringBuilder getTimeStamp(StringBuilder sb, long timeMilis, boolean time, boolean date) {
        synchronized (cal) {
            cal.setTimeInMillis(timeMilis);

            int f;
            if (time) {
                f = cal.get(Calendar.HOUR_OF_DAY);
                if (f < 10) {
                    sb.append("0");
                }
                sb.append(f);
                sb.append(":");
                f = cal.get(Calendar.MINUTE);
                if (f < 10) {
                    sb.append("0");
                }
                sb.append(f);
                sb.append(":");
                f = cal.get(Calendar.SECOND);
                if (f < 10) {
                    sb.append("0");
                }
                sb.append(f);
                sb.append(" ");
            }

            if (date) {
                f = cal.get(Calendar.MONTH);
                if (f < 10) {
                    sb.append("0");
                }
                sb.append(f);
                sb.append("/");
                f = cal.get(Calendar.DAY_OF_MONTH);
                if (f < 10) {
                    sb.append("0");
                }
                sb.append(f);
                sb.append("/");
                sb.append(cal.get(Calendar.YEAR));
            }

            return sb;
        }
    }
}

Related

  1. getTimeOnly(final Date oDate)
  2. getTimePart(Date dateObject)
  3. getTimePeriod(Date date)
  4. getTimerDate(String time)
  5. getTimeRoll(Date current, int field, int numberOfRoll)
  6. getTimeStampInMin(Date date)
  7. getTimeStampInSec(char separator, Date date)
  8. getTimestampl(Date time1, Date time2)
  9. getTimeStr(Date date, char delimiter)