• Java 获取系统时间


    1. Date类

    1 Date day=new Date();
    2 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    3 System.out.println(df.format(day));
    4 // 或者 
    5 Date date = new Date();    
    6 String year = String.format("%tY", date);
    7 String month = String.format("%tB", date);
    8 String day = String.format("%te", date);
    9 System.out.println(year+"-"+month+"-"+day);

    2. System类

    1 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    2 System.out.println(df.format(System.currentTimeMillis()));

    3. Calendar类

    1 Calendar c = Calendar.getInstance();//可以对每个时间域单独修改
    2 int year = c.get(Calendar.YEAR);
    3 int month = c.get(Calendar.MONTH);
    4 int date = c.get(Calendar.DATE);
    5 int hour = c.get(Calendar.HOUR_OF_DAY);
    6 int minute = c.get(Calendar.MINUTE);
    7 int second = c.get(Calendar.SECOND);
    8 System.out.println(year + "-" + month + "-" + date + " " +hour + ":" +minute + ":" + second);

     总结:系统时间可通过Date类、Calendar类和System中的currentTimeMillis来获取,时间格式可通过调用SimpleDateFormat类和String中的format方法来设置。

  • 相关阅读:
    1-4-04:奇偶ASCII值判断
    1-4-03:奇偶数判断
    1-4-02:输出绝对值
    1-4-01:判断数正负
    1-3-20:计算2的幂
    1-3-19:A*B问题
    1-3-18:计算三角形面积
    Use PIVOT Table in SQL Server
    Pivoting DataTable Simplified
    Pivot Methods 行列转换
  • 原文地址:https://www.cnblogs.com/tang-skillhunter/p/8612293.html
Copyright © 2020-2023  润新知