Java Second Format getFullDateByMisSecond(long misSecond)

Here you can find the source of getFullDateByMisSecond(long misSecond)

Description

get Full Date By Mis Second

License

Open Source License

Declaration

public static String getFullDateByMisSecond(long misSecond) 

Method Source Code


//package com.java2s;

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

public class Main {
    public static String getFullDateByMisSecond(long misSecond) {
        if (misSecond < 0) {
            throw new IllegalArgumentException("The misSecond must not be negative");
        }/*  w  w w  . j a  va  2s  .c  o  m*/
        if (misSecond == 0) {
            return "--";
        }
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(misSecond);
        java.util.Date date = cal.getTime();
        return getStrDate(date, "yyyy-MM-dd HH:mm:ss");

    }

    public static long getTime(Date dateParam) {
        if (dateParam == null) {
            throw new IllegalArgumentException("The dateParam  must not be null");
        }
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(dateParam.getTime());

        int hour = cal.get(Calendar.HOUR);
        int minute = cal.get(Calendar.MINUTE);
        int second = cal.get(Calendar.SECOND);

        long result = hour * 3600 * 1000 + minute * 60 * 1000 + second * 1000;

        return result;
    }

    public static String getStrDate(Date date, String format) {
        if (date == null || format == null) {
            return "";
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        String strDate = dateFormat.format(date);
        return strDate;
    }

    public static String getStrDate(Date date) {
        return getStrDate(date, "yyyy-MM-dd HH:mm:ss");
    }
}

Related

  1. formatTimeWithOutSeconds(java.util.Date d)
  2. getDHMS(long totalSecond)
  3. getElapsedSeconds(long startTime)
  4. getFormatMSecond(long long_)
  5. getFormattedDuration(int simTimeSeconds)
  6. getFutureDate(int seconds)
  7. getIntervalMilSeconds(String startDateStr, String endDateStr, String dateFormat)
  8. getMisSecond(String strDate)
  9. getSecond()