zoukankan      html  css  js  c++  java
  • 生成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(":","");
        }
    }
    生如夏花之绚烂,死如秋叶之静美。
  • 相关阅读:
    LD_PRELOAD的偷梁换柱之能
    ATOM & Sublime Text 下MarkDown插件功能比较
    存在
    2017年执行计划
    2015年总结以及2016年计划
    2014年总结以及2015年计划
    asp.net MVC中form提交和控制器接受form提交过来的数据
    2013年回顾及2014年计划
    c# XML序列化与反序列化
    Namenode HA原理详解(脑裂)
  • 原文地址:https://www.cnblogs.com/joyblabla/p/4835203.html
Copyright © 2011-2022 走看看