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)
  • 相关阅读:
    UIView常见方法总结
    ios UIview And Button TomCat
    (转)OC各种数据类型之间的转换方法
    8个改变让大脑变年轻
    (转)UIImageView响应点击事件
    ios UI 图片排列(简单实现)
    ios UIImage
    ios UIView 按钮
    html第一天--html常用标签
    工具软件类
  • 原文地址:https://www.cnblogs.com/zhuocheng/p/2351084.html
Copyright © 2011-2022 走看看