package com.tjzhxx.union.public_store;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.widget.DatePicker;
import android.widget.TimePicker;

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

/**
 * Created by Dong on 2016/10/20.
 */
public class TimeUtil {
    public static final String TIME_YYYY_MM = "yyyy-MM";
    public static final String TIME_YYYY_MM_DD = "yyyy-MM-dd";
    public static final String TIME_YYYY_MM_DD2 = "yyyy'/'MM'/'dd";
    public static final String TIME_YYYY_MM_DD3 = "yyyy.MM.dd";
    public static final String TIME_YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
    public static final String TIME_YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
    public static final String TIME_YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm";
    public static final String TIME_MM_DD_HH_MM = "MM-dd HH:mm";
    public static final String TIME_MM_DD_HH_MM_SS = "MM-dd HH:mm:ss";
    public static final String HH_MM = "HH:mm";
    public static final String TIME_HH_MM_SS = "HH:mm:ss";
    public static final String TIME_MM_DD = "MM-dd";
    public static final String TIME_DD = "dd";
    public static final String BEGIN_HH_MM_SS_ZAO = "00:01:00";
    public static final String END_HH_MM_SS_ZAO = "10:00:00";
    public static final String BEGIN_HH_MM_SS_ZHONG = "10:01:00";
    public static final String END_HH_MM_SS_ZHONG = "14:00:00";
    public static final String BEGIN_HH_MM_SS_WAN = "14:01:00";
    public static final String END_HH_MM_SS_WAN = "24:00:00";
    public static final String BEGIN_ORDER_HH_MM_SS = "00:00:00";
    public static final String END_ORDER_HH_MM_SS = "19:00:00";
    public static final String BEGIN_ORDER_HH_MM_SS_WAIMAI = "00:00:00";
    public static final String END_ORDER_HH_MM_SS_WAIMAI = "18:00:00";
    public static final String BEGIN_ORDER_HH_MM_SS_PROPERTY = "00:00:00";
    public static final String END_ORDER_HH_MM_SS_PROPERTY = "18:00:00";

    /**
     * 时间字符串格式化
     *
     * @param date      需要被处理的日期字符串
     * @param parseStr  需要被处理的日期的格式串
     * @param formatStr 最终返回的日期字符串的格式串
     * @return 已经格式化的日期字符串
     */
    public static String formatDate(String date, String parseStr,
                                    String formatStr) {
        if (TextUtils.isEmpty(date)) {
            return "";
        }

        SimpleDateFormat sdf = new SimpleDateFormat(parseStr);
        Date d = null;
        try {
            d = sdf.parse(date);
            sdf.applyPattern(formatStr);
            return sdf.format(d);
        } catch (ParseException e) {
            e.printStackTrace();
            return "";
        }
    }

    public static String formatDate(long date, String formatStr) {
//		if (date <= 0) {
//			return "";
//		}
        DateFormat sdf = new SimpleDateFormat(formatStr);
        try {
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(date);
            return sdf.format(calendar.getTime());
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    public static String formatDate(String date, String format) {
        if (TextUtils.isEmpty(date)) {
            return "";
        }
        String str = date;
        if (str.contains("T")) {
            str = str.replace("T", " ");
        }
        if (str.contains("/")) {
            str = str.replaceAll("/", "-");
        }
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        Date d = null;
        try {
            d = sdf.parse(str);
            return sdf.format(d);
        } catch (ParseException e) {
            e.printStackTrace();
            return "";
        }
    }

    public static String getWeak(long time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time);
        String week = "星期日";
        switch (calendar.get(Calendar.DAY_OF_WEEK)) {
            case 1:
                week = "星期日";
                break;
            case 2:
                week = "星期一";
                break;
            case 3:
                week = "星期二";
                break;
            case 4:
                week = "星期三";
                break;
            case 5:
                week = "星期四";
                break;
            case 6:
                week = "星期五";
                break;
            case 7:
                week = "星期六";
                break;
            default:
                break;
        }
        return week;
    }

    /**
     * 星期一 MON
     * 星期二 TUE
     * 星期三 WED
     * 星期四 THU
     * 星期五 FRI
     * 星期六 SAT
     * 星期天 SUN
     *
     * @param time
     * @return
     */
    public static String getWeak2(long time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time);
        String week = "SUN";//星期日
        switch (calendar.get(Calendar.DAY_OF_WEEK)) {
            case 1:
                week = "SUN";
                break;
            case 2:
                week = "MON";
                break;
            case 3:
                week = "TUE";
                break;
            case 4:
                week = "WED";
                break;
            case 5:
                week = "THU";
                break;
            case 6:
                week = "FRI";
                break;
            case 7:
                week = "SAT";//六
                break;
            default:
                break;
        }
        return week;
    }

    /**
     * @param time
     * @return
     */
    public static String getWeak3(long time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time);
        String week = "日";//星期日
        switch (calendar.get(Calendar.DAY_OF_WEEK)) {
            case 1:
                week = "日";
                break;
            case 2:
                week = "一";
                break;
            case 3:
                week = "二";
                break;
            case 4:
                week = "三";
                break;
            case 5:
                week = "四";
                break;
            case 6:
                week = "五";
                break;
            case 7:
                week = "六";//六
                break;
            default:
                break;
        }
        return week;
    }


    /**
     * 字符时间转换成Date
     *
     * @param value
     * @param format 需要的Date格式
     * @return
     */
    public static Date strToDate(String value, String format) {
        if (TextUtils.isEmpty(value)) {
            return new Date();
        }
        try {
            SimpleDateFormat formatter = new SimpleDateFormat(format);
            Date strtodate = formatter.parse(value);
            return strtodate;
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static long strToMillis(String time) {
        Date date = strToDate(time, "yyyy-MM-dd");
        if (date != null) {
            return date.getTime();
        } else {
            return 0;
        }
    }

    public static long strToMillis(String time, String format) {
        Date date = strToDate(time, format);
        if (date != null) {
            return date.getTime();
        } else {
            return 0;
        }
    }

    /**
     * 计算两个时间之间的相差天数，第二个参数减第一个参数
     *
     * @param first
     * @param second
     * @return
     */
    public static int compareDifference(long first, long second) {
        try {
            long time = second - first;
            int diff = (int) (time / 60 / 60 / 1000 / 24);
            return diff;
        } catch (Exception e) {
            return 0;
        }
    }

    /**
     * 比较两个日期大小，如果第一个小于第二个返回true
     *
     * @param first  yyyy-MM-dd
     * @param second yyyy-MM-dd
     * @param format yyyy-MM-dd
     * @return
     */
    public static boolean compareDate(String first, String second, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.CHINA);
        Date firstDate;
        try {
            firstDate = sdf.parse(first);
            Date secondDate = sdf.parse(second);
            return firstDate.before(secondDate);
        } catch (Exception e) {
            return false;
        }
    }

    /**
     * 比较两个日期大小，如果第一个小于第二个返回true
     *
     * @param firstDate Date
     * @param second
     * @param format    yyyy-MM-dd hh:mm:ss
     * @return
     */
    public static boolean compareDate(Date firstDate, String second, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.CHINA);
        Date secondDate;
        try {
            secondDate = sdf.parse(second);
            return firstDate.before(secondDate);
        } catch (Exception e) {
            return false;
        }
    }

    /**
     * 根据传入date获取前后多少天的日期
     *
     * @param date
     * @param day         正数就是后几天 负数就是前几天
     * @param returnParse 返回时间的格式
     * @return
     */
    public static String getDateByDay(String date, int day, String returnParse) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(strToMillis(date));
        calendar.add(Calendar.DAY_OF_MONTH, day);
        return formatDate(calendar.getTimeInMillis(), returnParse);
    }
    /**
     * 根据传入date获取前后多少月的日期
     *
     * @param date
     * @param day         正数就是后几月负数就是前几月
     * @param returnParse 返回时间的格式
     * @return
     */
    public static String getDateByMONTH(String date, int day, String returnParse) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(strToMillis(date));
        calendar.add(Calendar.MONTH, day);
        return formatDate(calendar.getTimeInMillis(), returnParse);
    }
    /**
     * 根据传入date获取前后多少年的日期
     *
     * @param date
     * @param year        正数就是后几年 负数就是前几年
     * @param returnParse 返回时间的格式
     * @return
     */
    public static String getDateByYear(String date, int year, String returnParse) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(strToMillis(date));
        calendar.add(Calendar.YEAR, year);
        return formatDate(calendar.getTimeInMillis(), returnParse);
    }

    /**
     * 比较两个日期的大小（前者大 返回true,比较到分钟数）
     *
     * @param one
     * @param two
     * @return
     */
    public static boolean compareDate(Date one, Date two) {
        if (one.getYear() > two.getYear()) {
            return true;
        } else if (one.getYear() == two.getYear()
                && one.getMonth() > two.getMonth()) {
            return true;
        } else if (one.getYear() == two.getYear()
                && one.getMonth() == two.getMonth()
                && one.getDate() > two.getDate()) {
            return true;
        } else if (one.getYear() == two.getYear()
                && one.getMonth() == two.getMonth()
                && one.getDate() == two.getDate()
                && one.getHours() > two.getHours()) {
            return true;
        } else if (one.getYear() == two.getYear()
                && one.getMonth() == two.getMonth()
                && one.getDate() == two.getDate()
                && one.getHours() == two.getHours()
                && one.getMinutes() > two.getMinutes()) {
            return true;
        } else {
            return false;
        }
    }

    public static String getTimeStrFromDatePicker(DatePicker date,
                                                  TimePicker time) {
        String timeStr = date.getYear() + "-";
        if (date.getMonth() + 1 < 10) {
            timeStr += "0" + (date.getMonth() + 1);
        } else {
            timeStr += (date.getMonth() + 1);
        }
        timeStr += "-";
        if (date.getDayOfMonth() < 10) {
            timeStr += "0" + date.getDayOfMonth();
        } else {
            timeStr += date.getDayOfMonth();
        }
        if (time != null) {
            if (time.getCurrentHour() < 10) {
                timeStr += " 0" + time.getCurrentHour();
            } else {
                timeStr += " " + time.getCurrentHour();
            }
            if (time.getCurrentMinute() < 10) {
                timeStr += ":0" + time.getCurrentMinute();
            } else {
                timeStr += ":" + time.getCurrentMinute();
            }
        }
        return timeStr;
    }

    /**
     * @param date
     * @return 1天5小时20分
     * @throws ParseException
     */
    @SuppressLint("SimpleDateFormat")
    public static String distanceDay(String date) {
        String reulst = "";

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        date = formatDate(date, "yyyy-MM-dd HH:mm:ss");
        // 给定的时间
        Date end = null;
        try {
            end = format.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        // 当前时间
        Date now = new Date();
        // 得到时间差
        long diff = (end.getTime() - now.getTime()) / 1000;
        long mm = (diff / 60) % 60;
        long hh = (diff / 60 / 60) % 24;
        long dd = (diff / 60 / 60 / 24);

        reulst = (dd + "天" + hh + "小时" + mm + "分");

        return reulst;
    }

    /**
     * @return 获取当前月第一天
     */
    @SuppressLint("SimpleDateFormat")
    public static String getMonthForFirstDay() {
        SimpleDateFormat format = new SimpleDateFormat(TIME_YYYY_MM_DD);
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.MONTH, 0);
        cal.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
        return format.format(cal.getTime());
    }

    /**
     * @return 获取当前月最后一天
     */
    @SuppressLint("SimpleDateFormat")
    public static String getMonthForLastDay() {
        SimpleDateFormat format = new SimpleDateFormat(TIME_YYYY_MM_DD);
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.DAY_OF_MONTH,
                cal.getActualMaximum(Calendar.DAY_OF_MONTH));
        return format.format(cal.getTime());
    }

    /**
     * 刚刚------2分钟及以内的
     * <p>
     * 今天 hh:mm------除了刚刚，且在当天24:00内的
     * <p>
     * yy-mm-dd hh:mm----除了以上的，就是它
     *
     * @param time
     * @return
     */
    public static String getProductHistory(long time) {
        String result = null;
        if ((System.currentTimeMillis() - time) <= 2 * 1000 * 60) {
            result = "刚刚";
        } else if (isSameDay(time, System.currentTimeMillis())) {
            result = "今天" + formatDate(time, HH_MM);
        } else {
            result = formatDate(time, TimeUtil.TIME_YYYY_MM_DD_HH_MM);
        }

        return result;
    }

    public static boolean isSameDay(long timeOne, long timeTwo) {
        Date dateOne = new Date(timeOne);
        Date dateTwo = new Date(timeTwo);
        if (dateOne.getYear() == dateTwo.getYear()
                && dateOne.getMonth() == dateTwo.getMonth()
                && dateOne.getDay() == dateTwo.getDay()) {
            return true;
        }
        return false;
    }


    public static boolean isYesterdayDay(long timeOne, long timeTwo) {
        Date dateOne = new Date(timeOne);
        Date dateTwo = new Date(timeTwo);
        if (dateOne.getYear() == dateTwo.getYear()
                && dateOne.getMonth() == dateTwo.getMonth()
                && (dateOne.getDay() == dateTwo.getDay() - 1)) {
            return true;
        }
        return false;
    }

    public static String getPostBoardHeaderTime(long time) {
        String result = null;
        if (isSameDay(time, System.currentTimeMillis())) {
            result = "今天";
        } else if (isYesterdayDay(time, System.currentTimeMillis())) {
            result = "昨天";
        } else {
            result = formatDate(time, TimeUtil.TIME_YYYY_MM_DD);
        }

        return result;
    }

    public static String getPostBoardHeaderTime(String time) {
        long localTime = strToMillis(
                formatDate(time, TIME_YYYY_MM_DD_HH_MM_SS),
                TIME_YYYY_MM_DD_HH_MM_SS);
        return getPostBoardHeaderTime(localTime);
    }

    /**
     * 截取格式 **年**月**日
     *
     * @param date
     * @return
     */
    public static String formatDate(String date) {
        if (TextUtils.isEmpty(date)) {
            return "";
        }
        date = formatDate(date, TIME_YYYY_MM_DD);
        String[] arr = date.split("-");
        if (arr != null && arr.length == 3) {
            String s = arr[0] + "年" + arr[1] + "月" + arr[2] + "日";
            return s;
        }
        return "";
    }

    /**
     * 当前时间推迟一年加一天
     *
     * @param format 返回数据的时间格式
     * @return
     */
    public static String getTheDayNextYear(String format) {
        String nextYear = "";
        try {
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) + 1);
            calendar.set(Calendar.DAY_OF_YEAR,
                    calendar.get(Calendar.DAY_OF_YEAR) + 1);
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            nextYear = sdf.format(calendar.getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return nextYear;
    }

    /**
     * 返回年
     *
     * @return
     */
    public static String getCurrentYear() {
        String result = "";
        try {
            Calendar calendar = Calendar.getInstance();
            int year = calendar.get(Calendar.YEAR);
            result = year + "";
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    /**
     * 返回月
     *
     * @return
     */
    public static String getCurrentMoth() {
        String result = "";
        try {
            Calendar calendar = Calendar.getInstance();
            int moth = calendar.get(Calendar.MONTH);
            moth++;
            result = moth + "";
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    /**
     * 返回今天
     *
     * @return
     */
    public static String getCurrentDayofMoth() {
        String result = "";
        try {
            Calendar calendar = Calendar.getInstance();
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            result = day + "";
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    /**
     * 获取日期
     *
     * @param pattern
     * @return
     */
    public static String getCurrentDayStr(String pattern) {
        String result = "";
        try {
            Calendar calendar = Calendar.getInstance();
            result = formatDate(calendar.getTimeInMillis(), pattern);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;

    }


    /**
     * 判断时间是否在时间段内
     *
     * @param strDate      当前时间 yyyy-MM-dd HH:mm:ss
     * @param strDateBegin 开始时间 00:00:00
     * @param strDateEnd   结束时间 00:05:00
     * @return
     */
    public static boolean isInDate1(String strDate, String strDateBegin, String strDateEnd) {
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        try {
            Date nowTime = sdf.parse(strDate);
            Date startTime = sdf.parse(strDateBegin);
            Date endTime = sdf.parse(strDateEnd);
            if (nowTime.getTime() == startTime.getTime()
                    || nowTime.getTime() == endTime.getTime()) {
                return true;
            }

            Calendar date = Calendar.getInstance();
            date.setTime(nowTime);

            Calendar begin = Calendar.getInstance();
            begin.setTime(startTime);

            Calendar end = Calendar.getInstance();
            end.setTime(endTime);

            if (date.after(begin) && date.before(end)) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            return false;
        }
    }
    /**
     * 判断时间是否在时间段内(测试不对)
     *
     * @param date         当前时间 new Date()
     * @param strDateBegin 开始时间 00:00:00
     * @param strDateEnd   结束时间 00:05:00
     * @return
     */
    public static boolean isInDate(Date date, String strDateBegin, String strDateEnd) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String strDate = sdf.format(date);
        // 截取当前时间时分秒
        int strDateH = Integer.parseInt(strDate.substring(11, 13));
        int strDateM = Integer.parseInt(strDate.substring(14, 16));
        int strDateS = Integer.parseInt(strDate.substring(17, 19));
        // 截取开始时间时分秒
        int strDateBeginH = Integer.parseInt(strDateBegin.substring(0, 2));
        int strDateBeginM = Integer.parseInt(strDateBegin.substring(3, 5));
        int strDateBeginS = Integer.parseInt(strDateBegin.substring(6, 8));
        // 截取结束时间时分秒
        int strDateEndH = Integer.parseInt(strDateEnd.substring(0, 2));
        int strDateEndM = Integer.parseInt(strDateEnd.substring(3, 5));
        int strDateEndS = Integer.parseInt(strDateEnd.substring(6, 8));
        if ((strDateH >= strDateBeginH && strDateH <= strDateEndH)) {
            // 当前时间小时数在开始时间和结束时间小时数之间
            if (strDateH > strDateBeginH && strDateH < strDateEndH) {
                return true;
                // 当前时间小时数等于开始时间小时数，分钟数在开始和结束之间
            } else if (strDateH == strDateBeginH && strDateM >= strDateBeginM
                    && strDateM <= strDateEndM) {
                return true;
                // 当前时间小时数等于开始时间小时数，分钟数等于开始时间分钟数，秒数在开始和结束之间
            } else if (strDateH == strDateBeginH && strDateM == strDateBeginM
                    && strDateS >= strDateBeginS && strDateS <= strDateEndS) {
                return true;
            }
            // 当前时间小时数大等于开始时间小时数，等于结束时间小时数，分钟数小等于结束时间分钟数
            else if (strDateH >= strDateBeginH && strDateH == strDateEndH
                    && strDateM <= strDateEndM) {
                return true;
                // 当前时间小时数大等于开始时间小时数，等于结束时间小时数，分钟数等于结束时间分钟数，秒数小等于结束时间秒数
            } else if (strDateH >= strDateBeginH && strDateH == strDateEndH
                    && strDateM == strDateEndM && strDateS <= strDateEndS) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    /**
     * 判断时间是否在时间段内
     *
     * @param strDate      当前时间 yyyy-MM-dd HH:mm:ss
     * @param strDateBegin 开始时间 00:00:00
     * @param strDateEnd   结束时间 00:05:00
     * @return
     */
    public static boolean isInDate(String strDate, String strDateBegin, String strDateEnd) {
        // 截取当前时间时分秒
        int strDateH = Integer.parseInt(strDate.substring(11, 13));
        int strDateM = Integer.parseInt(strDate.substring(14, 16));
        int strDateS = Integer.parseInt(strDate.substring(17, 19));
        // 截取开始时间时分秒
        int strDateBeginH = Integer.parseInt(strDateBegin.substring(0, 2));
        int strDateBeginM = Integer.parseInt(strDateBegin.substring(3, 5));
        int strDateBeginS = Integer.parseInt(strDateBegin.substring(6, 8));
        // 截取结束时间时分秒
        int strDateEndH = Integer.parseInt(strDateEnd.substring(0, 2));
        int strDateEndM = Integer.parseInt(strDateEnd.substring(3, 5));
        int strDateEndS = Integer.parseInt(strDateEnd.substring(6, 8));
        if ((strDateH >= strDateBeginH && strDateH <= strDateEndH)) {
            // 当前时间小时数在开始时间和结束时间小时数之间
            if (strDateH > strDateBeginH && strDateH < strDateEndH) {
                return true;
                // 当前时间小时数等于开始时间小时数，分钟数在开始和结束之间
            } else if (strDateH == strDateBeginH && strDateM >= strDateBeginM
                    && strDateM <= strDateEndM) {
                return true;
                // 当前时间小时数等于开始时间小时数，分钟数等于开始时间分钟数，秒数在开始和结束之间
            } else if (strDateH == strDateBeginH && strDateM == strDateBeginM
                    && strDateS >= strDateBeginS && strDateS <= strDateEndS) {
                return true;
            }
            // 当前时间小时数大等于开始时间小时数，等于结束时间小时数，分钟数小等于结束时间分钟数
            else if (strDateH >= strDateBeginH && strDateH == strDateEndH
                    && strDateM <= strDateEndM) {
                return true;
                // 当前时间小时数大等于开始时间小时数，等于结束时间小时数，分钟数等于结束时间分钟数，秒数小等于结束时间秒数
            } else if (strDateH >= strDateBeginH && strDateH == strDateEndH
                    && strDateM == strDateEndM && strDateS <= strDateEndS) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    public static String GetNowDate() {
        String temp_str = "";
        Date dt = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        temp_str = sdf.format(dt);
        return temp_str;
    }

    public static Calendar getCalendar(String date, String pattern) {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat df = new SimpleDateFormat(pattern);
        Date daystart = null;
        try {
            daystart = df.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
        calendar.setTime(daystart);
        return calendar;
    }

    //当前时间属于早中晚
    public static String getDateString() {
        String s = "早上好，";
        Calendar cal = Calendar.getInstance();
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        if (hour >= 6 && hour < 11) {
            s = "早上好，";
        } else if (hour >= 11 && hour < 18) {
            s = "中午好，";
        } else  {
            s = "晚上好，";
        }
        return s;
    }
}
