Java Date to Time getTimeDateStr(Date date)

Here you can find the source of getTimeDateStr(Date date)

Description

get Time Date Str

License

Open Source License

Declaration

public static final String getTimeDateStr(Date date) 

Method Source Code

//package com.java2s;

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static final String getTimeDateStr(Date date) {
        if (date == null) {
            return null;
        }/* ww w .j  a  v  a 2s .  co  m*/
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return getFixedTwoStr(cal.get(Calendar.HOUR_OF_DAY)) + ":" + getFixedTwoStr(cal.get(Calendar.MINUTE)) + " "
                + cal.get(Calendar.DAY_OF_MONTH) + "/" + (cal.get(Calendar.MONTH) + 1) + "/"
                + cal.get(Calendar.YEAR);
    }

    public static String getFixedTwoStr(int i) {
        String fixedTwoStr = i + "";
        if (i < 10) {
            fixedTwoStr = "0" + i;
        }
        return fixedTwoStr;
    }
}

Related

  1. getTimeBackInMillis(final int granularity, final int numberToBack, final Date date)
  2. getTimeBoxValue(TimeZone zone, Date date)
  3. getTimeByCustomPattern(Date date, String pattern)
  4. getTimeByOffset(Date reqDate, int offset)
  5. getTimeDateByMinuteAndSeconds( Integer minutes, Integer seconds)
  6. getTimeDeltaValue(Date t, Date baseDate, String tDelta)
  7. getTimeFromDate(Date date)
  8. getTimeFromDate(final Date date)
  9. getTimeImMillis(Date date)