package com.sheep.gamegroup.util;

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

/**
 * Created by ljy on 2018/3/8.
 */
public class TimeUtil {

    public static String FORMAT = "yyyy/MM/dd HH:mm";

    public static long getCurrentSeconds(){
        long ls = System.currentTimeMillis()/1000;
        return ls;
    }
    public static String TimeStamp2Date(long time, String formats) {
        time = time < 10_000_000_000L ? time * 1000 : time;//秒的时间戳为10位数,要x1000  10_000_000_000L对应时间为2286-11-21 01:46:40
        String date = new SimpleDateFormat(formats, Locale.CHINA).format(new Date(time));
        return date;
    }
    public static String[] getCalendarShowTime(long paramLong)
    {
        String[] localObject;
        String str = new SimpleDateFormat("yyyy:MM:dd", Locale.ENGLISH).format(new Date(paramLong));
        try
        {
            String[] arrayOfString = str.split(":");
            localObject = arrayOfString;
            if ((localObject != null) && (localObject.length == 3));
            return localObject;
        }
        catch (Exception localException)
        {
            while (true)
                localException.printStackTrace();
        }
    }

    public static String[] getCalendarShowTime(String paramString)
    {
        try {
            long l = Long.valueOf(paramString);
            Calendar localCalendar = Calendar.getInstance();
            localCalendar.setTimeInMillis(1000L * l);
            return getCalendarShowTime(localCalendar.getTimeInMillis());
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static String getDate(String formate){
        String str = new SimpleDateFormat(formate, Locale.ENGLISH).format(new Date());
        return str;
    }
    public static String getDate(String formate, long paramLong){
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(paramLong*1000);
        Date date = c.getTime();
        String str = new SimpleDateFormat(formate, Locale.ENGLISH).format(date);
        return str;
    }

    /**
     * 毫秒值
     * @param time
     * @return 时:分:秒
     */
    public static String getHours(long time) {
        long second = time / 1000;
        long hour = second / 60 / 60;
        long minute = (second - hour * 60 * 60) / 60;
        long sec = (second - hour * 60 * 60) - minute * 60;

        String rHour = "";
        String rMin = "";
        String rSs = "";
        // 时
        if (hour < 10) {
            rHour = "0" + hour;
        } else {
            rHour = hour + "";
        }
        // 分
        if (minute < 10) {
            rMin = "0" + minute;
        } else {
            rMin = minute + "";
        }
        // 秒
        if (sec < 10) {
            rSs = "0" + sec;
        } else {
            rSs = sec + "";
        }

        // return hour + "小时" + minute + "分钟" + sec + "秒";
        return rHour + ":" + rMin + ":" + rSs;

    }

}
