zoukankan      html  css  js  c++  java
  • java中获得时间及个别操作

    
    


    // 博客搬家咯~ http://joeleee.github.io/

    
    

    // 博客搬家咯~ http://joeleee.github.io/

    
    

    // 博客搬家咯~ http://joeleee.github.io/




    public
    static void main(String[] args) {

    SimpleDateFormat matter = new SimpleDateFormat("yyyy-MM-dd_HH:mm"); // 自定义时间格式

    Calendar calendar = Calendar.getInstance(); // 获得当前时间
    Date date1 = calendar.getTime(); // 将calendar的时间赋值给date1
    calendar.add(Calendar.MINUTE, -100); // 将calendar的时间减去100分钟
    Date date2 = calendar.getTime(); // 将calendar的时间赋值给date2
    Date date3 = null;

    try {
    date3 = matter.parse("1989-05-18_10:21"); // 按照自定义的格式自定时间
    } catch (ParseException e) {
    e.printStackTrace();
    }
    String str1 = matter.format(date1); // 将date1格式化为自定义时间格式的字符串
    String str2 = matter.format(date2); // 将date2格式化为自定义时间格式的字符串
    String str3 = matter.format(date3); // 将date3格式化为自定义时间格式的字符串

    System.out.println(str1); // 输出
    System.out.println(str2); // 输出
    System.out.println(str3); // 输出
    System.out.println(date1.after(date2)); // 比较date1和date2

    System.exit(0);
    return;
    }
    From zhuocheng (cnblogs.com/zhuocheng)
  • 相关阅读:
    Alpha 冲刺 (1/10)
    项目需求分析答辩总结
    项目UML设计(团队)
    第七次作业--项目需求分析(团队)
    第六次作业--结对编程第二次
    第四次作业--项目选题报告(团队)
    第二次结对作业
    第一次结对编程作业
    第7组 团队展示
    js学习笔记
  • 原文地址:https://www.cnblogs.com/zhuocheng/p/2351084.html
Copyright © 2011-2022 走看看