生成yyMMddHHmmssSS时间戳代码作为唯一主键值

import java.sql.Time;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.mvel.util.ThisLiteral;


public class DateTools {
    public static boolean timeeqtime(String ta, String tb) {
        boolean flag = false;
        try {
            String fmt = ""; // 譬如要format为yyyyMM-dd
            fmt = "yyyy-MM-dd";
            SimpleDateFormat sdf = new SimpleDateFormat(fmt);
            // Date date = new Date();
            // String dateStr = sdf.format(date);
            // System. out.println(dateStr);
            Date tta = sdf.parse(ta);
            Date ttb = sdf.parse(tb);
            flag = (tta.getTime() == ttb.getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return flag;
    }    
    public static Date getDate(String str) {
        Date d = null;
        if (str == null || str.equals("")) {
            return null;
        } else {
            DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            try {
                d = format.parse(str);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return d;
    }
    public static String getDateTime() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(new Date());
    }
    public static String getDateTimeSSS() {
        SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd HH:mm:ss:SSS");
        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return sdf.format(new Date());
    }
    public static String getDateXXX() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
        return sdf.format(new Date());
    }
    public static String getDateTimeString() {
        return getDateTime().trim().replace("-","").replace(" ","").replace(":","");
    }
    public static String getDateTimeStringSSS() {        
        return getDateTimeSSS().trim().replace("-","").replace(" ","").replace(":","");
    }
}

 

转载于:https://www.cnblogs.com/joyblabla/p/4835203.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值