package com.quinn.utils;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

public class QuinnUtils {

    private static final String ALLCHAR = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private final static SimpleDateFormat sdf =  new SimpleDateFormat( "yyyyMMdd");
    private final static SimpleDateFormat sdfv =  new SimpleDateFormat( "yyyy-MM-dd");

    public static String getUuid(){
        return UUID.randomUUID().toString().replaceAll("-","");
    }

    public static Timestamp getTime(){
        return new Timestamp(new Date().getTime());
    }

    public static String getStrFromDate(Date date){
        return sdf.format(date);
    }

    public static String getViewStrFromDate(Date date){
        return sdfv.format(date);
    }

    public static String getCode(){
        int length = 6;
        //随机数
        StringBuffer sb = new StringBuffer();
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            sb.append(ALLCHAR.charAt(random.nextInt(ALLCHAR.length())));
        }
        return sb.toString();
    }

}
