Java Long Number to Date dateToStrLong(java.util.Date dateDate, String format)

Here you can find the source of dateToStrLong(java.util.Date dateDate, String format)

Description

date To Str Long

License

Open Source License

Declaration

public static String dateToStrLong(java.util.Date dateDate, String format) 

Method Source Code

//package com.java2s;

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

public class Main {

    public static String dateToStrLong(java.util.Date dateDate) {

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String dateString = formatter.format(dateDate);

        return dateString;

    }// ww  w  .j  a  v  a2s.  com

    public static String dateToStrLong(java.util.Date dateDate, String format) {

        SimpleDateFormat formatter = new SimpleDateFormat(format);

        String dateString = formatter.format(dateDate);

        return dateString;

    }

    public static String format(java.util.Date date, String format, Calendar calendar) {
        String result = "";
        try {
            if (date != null) {
                java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(format);
                if (calendar != null) {
                    sdf.setCalendar(calendar);
                }
                result = sdf.format(date);
            }
        } catch (Exception e) {
        }

        return result;
    }

    public static String format(java.util.Date date, String format) {
        return format(date, format, null);
    }

    public static String format(long times, String format) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(times);
        return format(calendar.getTime(), format);
    }

    public static String getTime() {

        Date currentTime = new Date();

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String dateString = formatter.format(currentTime);

        String min;

        min = dateString.substring(14, 16);

        return min;

    }
}

Related

  1. dateToString(long date)
  2. dateToString(long date)
  3. dateToString(long date)
  4. dateToString(long date)
  5. dateToString(long date, String formate)
  6. format(long date)
  7. format(Long date, String pattern)
  8. format(long date, String pattern)
  9. format(long dateInMillis, String pattern)