Java Milliseconds Parse changeMillSecond2Date(long millSeconds)

Here you can find the source of changeMillSecond2Date(long millSeconds)

Description

change Mill Second Date

License

Apache License

Declaration

public static String changeMillSecond2Date(long millSeconds) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Locale;

public class Main {
    private static final String patternDate = "yyyy-MM-dd";
    private static final String patternDateTime = "yyyy-MM-dd HH:mm:ss";
    private static final String patternDateMinutes = "yyyy-MM-dd HH:mm";

    public static String changeMillSecond2Date(long millSeconds) {
        Date temp = new Date(millSeconds);
        return formatDateMinutes(temp);
    }//from   www  . j  a v a2 s .  c  o  m

    public static String changeMillSecond2Date(long millSeconds, String pattern) {
        Date temp = new Date(millSeconds);
        return formatDateMinutes(temp, pattern);
    }

    public static String formatDateMinutes(Date myDate) {
        return formatDateTime(myDate, patternDateMinutes);
    }

    public static String formatDateMinutes(Date myDate, String pattern) {
        return formatDateTime(myDate, pattern);
    }

    public static String formatDateTime(Date myDate, String pattern) {
        myDate = isDate(myDate);
        // SimpleDateFormat fd = new SimpleDateFormat(pattern, Locale.CHINA);
        SimpleDateFormat fd = new SimpleDateFormat(pattern);
        return (fd.format(myDate));
    }

    public static String formatDateTime(String myDate, String pattern) {
        if (myDate.length() > 10)
            myDate = myDate.substring(0, 10);
        Date date = getDateByString(myDate, "yyyy-MM-dd");
        return formatDateTime(date, pattern, Locale.US);
    }

    public static String formatDateTime(Date myDate, String pattern, Locale localcode) {
        myDate = isDate(myDate);
        SimpleDateFormat fd = new SimpleDateFormat(pattern, localcode);
        return (fd.format(myDate));
    }

    public static String formatDateTime(Date myDate) {
        return formatDateTime(myDate, patternDateTime);
    }

    public static Date isDate(Date myDate) {
        // if (myDate == null)
        // return new Date();
        return myDate;
    }

    public static Date getDateByString(String rq) {
        // DateFormat df = DateFormat.getDateInstance();
        DateFormat df = new SimpleDateFormat(patternDate);
        Date d = null;
        try {
            d = df.parse(rq);
        } catch (Exception e) {
            // e.printStackTrace();
        }
        return d;
    }

    public static Date getDateByString(String str, String pattern) {
        SimpleDateFormat sdf = null;
        try {
            sdf = new SimpleDateFormat(pattern);
        } catch (Exception ex) {
            sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        }
        try {
            return sdf.parse(str);
        } catch (Exception e) {
        }
        return null;
    }
}

Related

  1. getTimeAsMillis(String value)
  2. getTimeFromMilliseconds(long ms)
  3. getTimeInMilliseconds(String timeString)
  4. getTimeMillis(long FileTimestamp)