package com.danding.yang800.Util;

import org.apache.commons.codec.binary.Base64;
import org.json.JSONObject;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * Created by Administrator on 2017/9/28.
 */
public class StringUtil {
    public static String doubleToString(JSONObject jsonObject, String key) {
        try {
            double storeTotalIncomeDouble = jsonObject.getDouble(key);
            String result = new DecimalFormat("0.00").format(storeTotalIncomeDouble);
            return result;
        } catch (Exception e) {
            return "";
        }
    }
    public static String getDouble(JSONObject jsonObject, String key) {
        try {
            double storeTotalIncomeDouble = jsonObject.getDouble(key);
            String result = new DecimalFormat("0.00").format(storeTotalIncomeDouble);
            return result;
        } catch (Exception e) {
            return "0.00";
        }
    }

    public static String doubleToString(double data) {
        try {
            String result = new DecimalFormat("0.00").format(data);
            return result;
        } catch (Exception e) {
            return "";
        }
    }

    public static boolean getString(String str) {
        if (str == null || str.equals("")) {
            return false;
        } else {
            return true;
        }

    }

    public static String toString(Object o) {
        if (o == null) {
            return "";
        } else if (o.toString().equals("null")) {
            return "";
        }
        return o.toString();
    }

    public static String[] splitDouble(String str) {
        String[] split = str.split("\\.");
//        for (String s : split) {
//        }
        return split;
    }

    public static String getStrTime(String time) {
        String re_StrTime = null;
        SimpleDateFormat sdf = null;
        if (time.equals("")) {
            return "";
        }
        sdf = new SimpleDateFormat("yyyy.MM.dd");
        long loc_time = Long.valueOf(time);
        re_StrTime = sdf.format(new Date(loc_time * 1000L));
        return re_StrTime;
    }

    public static byte[] base64Decrypt(byte[] content) {
        byte[] contentBytes = Base64.decodeBase64(content);
        return contentBytes;
    }

    public static String getcurrentTime() {
        SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String date = sDateFormat.format(new java.util.Date());
        return date;
    }

    public static boolean isDateOneBigger(String str1, String str2) {
        boolean isBigger = false;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dt1 = null;
        Date dt2 = null;
        try {
            dt1 = sdf.parse(str1);
            dt2 = sdf.parse(str2);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if (dt1.getTime() <= dt2.getTime()) {
            isBigger = true;
        } else {
            isBigger = false;
        }
        return isBigger;
    }


}


