package com.bohuikeji.frame.module.admin.utils.wx;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

import java.util.Date;
import java.util.Random;
import java.util.TimeZone;

public class DateUtil {
    /**
     * 转换rfc3339格式时间
     *
     * @param date 时间
     * @return rfc3339Date
     */
    public static String getRfc3339(Date date) {
        DateTime rfc3339Date = new DateTime(date, DateTimeZone.forTimeZone(TimeZone.getTimeZone("Asia/Shanghai")));
        return rfc3339Date.toString();
    }


    /**
     * 生成随机字符串
     *
     * @param length
     * @return
     */
    public static String getRandomString2(int length) {
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; ++i) {
            int number = random.nextInt(3);
            long ResponseObj = 0;

            switch (number) {
                case 0:
                    ResponseObj = Math.round(Math.random() * 25 + 65);
                    sb.append((char) ResponseObj);
                    break;
                case 1:
                    ResponseObj = Math.round(Math.random() * 25 + 97);
                    sb.append((char) ResponseObj);
                    break;
                case 2:
                    sb.append(new Random().nextInt(10));
                    break;
                default:
            }
        }
        return sb.toString();
    }
}
