zoukankan      html  css  js  c++  java
  • Date类

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

    import javax.swing.JOptionPane;

    public class DateUtil {
    private DateUtil(){
    }
    public static String long2String(long d){
    Date date = new Date(d);
    DateFormat df = new SimpleDateFormat("yyyy年MM月dd HH:mm:ss");
    String str = df.format(date);
    return str;
    }
    /*
    * 代码抽取技术:
    * 首先不要想“抽出的方法”怎么写,而是把类似的代码拷在一起,观察其中的变化部分和不变化部分。
    * 把这段代码中用到的“前面定义的变量”抽取成方法的参数--本例中为txtInDate和erroInfo,把“留给后面使用的”将在这段代码中新
    * 创建的变量定义成方法的返回值---本例为inDate。
    */

    public static long string2long(String txtInDate,String erroInfo){//要考虑参数和返回值
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    long inDate = 0;
    try {
    Date d = df.parse(txtInDate);
    inDate = d.getTime();
    } catch (ParseException e) {
    JOptionPane.showMessageDialog(null, erroInfo);
    return -1;
    }
    return inDate;
    }

    }

  • 相关阅读:
    树上莫队 SPOJ COT2
    UVA 11478(差分约束 + 二分)
    可图的度序列判断与构造
    Codeforces Round #306 (Div. 2) 550A Two Substrings
    UVA 11300 分金币
    HDU 2546 饭卡(01 背包)
    hdu 1142 最短路+记忆化
    codeforces ice cave
    codeforces school mark(贪心)
    JavaScript函数
  • 原文地址:https://www.cnblogs.com/1314wamm/p/5603396.html
Copyright © 2011-2022 走看看