Java Hour Format formateDaTime(Date date)

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

Description

formate Da Time

License

Open Source License

Declaration

public static String formateDaTime(Date date) 

Method Source Code

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

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

public class Main {
    /**/*from w  w w  .  j a  v a2  s. c o m*/
     * @param yyyy:MM:dd
     *            HH:mm:ss
     * @return
     */
    public static final String patternD = "yyyy-MM-dd HH:mm:ss";

    public static String formateDaTime(Date date) {
        return dateToString(date, patternD);
    }

    public static String dateToString(Date date, String pattern) {
        if (date == null) {
            return "";
        } else {
            SimpleDateFormat format = new SimpleDateFormat(pattern);
            return format.format(date);
        }
    }

    public static String dateToString(int year, int month, int day, String pattern) {
        return dateToString(getDate(year, month, day), pattern);
    }

    public static Date getDate() {
        return Calendar.getInstance().getTime();
    }

    public static Date getDate(int year, int month, int day) {
        Calendar cal = Calendar.getInstance();
        cal.set(year, month - 1, day, 0, 0, 0);
        return cal.getTime();

    }

    public static Date getDate(int year, int month, int date, int hour, int mintue, int second) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month - 1);
        cal.set(Calendar.DATE, date);
        cal.set(Calendar.HOUR_OF_DAY, hour);
        cal.set(Calendar.MINUTE, mintue);
        cal.set(Calendar.SECOND, second);
        return cal.getTime();
    }
}

Related

  1. formatDuration(long value)
  2. formateDataC(Date date)
  3. formateDate(Date date)
  4. formateDate(Date date, String format)
  5. forMateDate(String dateStr)
  6. formateEndTimeString(String time)
  7. formatEndTime(String datePre)
  8. formatFF(String date)
  9. formatFileDate(Date from)