zoukankan      html  css  js  c++  java
  • 常用函数

     // 得到今天日期, 格式为"yyyy-MM-dd"
     public static String getTodayString() {
      SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd");
      String strdt = SDF.format(new java.util.Date());
      return strdt;
     }

     // 得到今天时间, 格式为"yyyyMMddhhmmss"
     public String getNowTimeString() {
      SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
      String strdt = SDF.format(new java.util.Date());
      return strdt;
     }

     // 加密函数,密码加密
    public static String encrypt_pwd(String pwd) {
      return pwd;
     }

     // 加密函数,字符串加密
    public static String encrypt_pwd(String pwd) {
      return pwd;
     }

     //判断是否为数字
     public boolean isNumeric(String str)
     {
      Pattern pattern = Pattern.compile("[0-9]*");
      Matcher isNum = pattern.matcher(str);
       if( !isNum.matches() )
       {
        return false; //不是数字
       }
      return true; //是数字
     }

    // 将Date转化为String, 格式为"yyyy-MM-dd HH:mm:ss"
     public static String convertDateToString(Date dt) {
      SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      String strdt = SDF.format(dt);
      return strdt;
     }

     // 将String转化为Date, 要求String格式为"yyyy-MM-dd HH:mm:ss"
     public static Date convertStringToDate(String strdt) {
      SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      Date dt = null;
      try {
       dt = SDF.parse(strdt);
      } catch (Exception e) {
       logger.error("Can't convert '" + strdt + "' to Date: "
         + e.getMessage());
      }
      return dt;
     }

     // 得到今天日期, 格式为"yyyy-MM-dd"
     public static String getTodayStr() {
      SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      String strdt = SDF.format(new java.util.Date());
      return strdt;
     }

     // 得到今天时间, 格式为"yyyyMMddhhmmss"
     public static String getNowTime() {
      SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      String strdt = SDF.format(new java.util.Date());
      return strdt;
     }

     // 得到min分钟后的时间
     public static String getDTAfterMin(Date dt, int min) {
      Date newdt = dt;

      newdt.setTime(newdt.getTime() + min * 60000);
      return convertDateToString(newdt);
     }

     // 解决中文查询问题
     public static String chgStr(String str) {

      if (str == null)
       return null;

      try {
       byte[] temp_t = str.getBytes("ISO-8859-1");
       return new String(temp_t);
      } catch (Exception e) {
       logger.error("Can't chgStr '" + str + "': " + e.getMessage());
       return null;
      }
     }

  • 相关阅读:
    【学车笔记】皮卡科目二考前笔记
    【Java学习笔记】继承和多态
    【Java学习笔记】Java中定义宏
    【读书笔记】《世界上最伟大的推销员》
    《大话设计模式》重印公告
    《大话设计模式》第29章OOTV杯超级模式大赛—模式总结(四)
    《大话设计模式》第29章OOTV杯超级模式大赛—模式总结(六)
    《大话设计模式》第29章OOTV杯超级模式大赛—模式总结(五)
    阅读不懂,图书之过——《大话设计模式》创作历程
    岁月凶残,敬请珍惜——得知早已不能过五四节时之随想
  • 原文地址:https://www.cnblogs.com/xinxindiandeng/p/1348421.html
Copyright © 2011-2022 走看看