Java Millisecond Convert millisecondToDate(String str)

Here you can find the source of millisecondToDate(String str)

Description

millisecond To Date

License

Apache License

Declaration

public static String millisecondToDate(String str) 

Method Source Code

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

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.GregorianCalendar;

public class Main {

    public static String millisecondToDate(String str) {
        long ms = Long.parseLong(str);
        Date dat = new Date(ms * 1000);
        //      //System.out.println(dat);
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(dat);/* w w w .j ava  2s  . c  om*/
        //        //System.out.println(gc.getTime());
        SimpleDateFormat format = new SimpleDateFormat(
                "yyyy-MM-dd hh:mm:ss");
        String sb = format.format(gc.getTime());
        return sb;
    }

    public static Date getTime() {
        try {
            return getDate("yyyy-MM-dd HH:mm:ss");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Date getDate() {
        try {
            return getDate("yyyy-MM-dd");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Date getDate(String format) throws ParseException {
        SimpleDateFormat df = new SimpleDateFormat(format);
        Date date = new Date(System.currentTimeMillis());
        return convertStringToDate(df.format(date), format);
    }

    public static Date convertStringToDate(String time, String format)
            throws ParseException {
        if (format == null) {
            format = "yyyy-MM-dd";
        }
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.parse(time);
    }
}

Related

  1. millisecondsToString(long time)
  2. millisecondsToTimerString(long millis)
  3. millisecondsToTimestamp(final long milliseconds)
  4. millisecondsToTimeString(int milliseconds)
  5. millisecondToDate(long timeMillis)
  6. millisecondToDHMS(long duration)
  7. millisecsToSecs(long millisecs)
  8. milliSecsToTime(double current, double max, double buffer)
  9. milliSecToString(final long mS)