Java Date to Time getTimeStampInMin(Date date)

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

Description

get Time Stamp In Min

License

Open Source License

Declaration

public static String getTimeStampInMin(Date date) 

Method Source Code

//package com.java2s;
/**//from   w w w .j  a v  a  2 s .  com
 * Project: zonda.logger.server
 *
 * File Created at 12-2-3
 * DateUtil: DateUtil.java 12-2-3 darwin $
 *
 * Copyright 2008 Alibaba.com Croporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Alibaba Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Alibaba.com.
 */

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

public class Main {
    public static String getTimeStampInMin(char separator, Date date) {
        Calendar cal = Calendar.getInstance();
        if (date != null)
            cal.setTime(date);
        StringBuilder sb = new StringBuilder();
        sb.append(cal.get(Calendar.YEAR));
        sb.append(separator);
        sb.append(padding(cal.get(Calendar.MONTH) + 1));
        sb.append(separator);
        sb.append(padding(cal.get(Calendar.DAY_OF_MONTH)));
        sb.append(separator);
        sb.append(padding(cal.get(Calendar.HOUR_OF_DAY)));
        sb.append(separator);
        sb.append(padding(cal.get(Calendar.MINUTE)));
        return sb.toString();
    }

    public static String getTimeStampInMin(Date date) {
        Calendar cal = Calendar.getInstance();
        if (date != null)
            cal.setTime(date);
        StringBuilder sb = new StringBuilder();
        sb.append(cal.get(Calendar.YEAR));
        sb.append(padding(cal.get(Calendar.MONTH) + 1));
        sb.append(padding(cal.get(Calendar.DAY_OF_MONTH)));
        sb.append("/");
        sb.append(padding(cal.get(Calendar.HOUR_OF_DAY)));
        sb.append("/");
        sb.append(padding(cal.get(Calendar.MINUTE)));
        return sb.toString();
    }

    public static String padding(int i) {
        if (i == 0)
            return "00";
        else if (i < 10)
            return "0" + i;
        else
            return "" + i;
    }
}

Related

  1. getTimePart(Date dateObject)
  2. getTimePeriod(Date date)
  3. getTimerDate(String time)
  4. getTimeRoll(Date current, int field, int numberOfRoll)
  5. getTimeStamp(long timeMilis, boolean time, boolean date)
  6. getTimeStampInSec(char separator, Date date)
  7. getTimestampl(Date time1, Date time2)
  8. getTimeStr(Date date, char delimiter)
  9. getTimeString(Date d)