zoukankan      html  css  js  c++  java
  • java日期函数工具类

    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.GregorianCalendar;
     
    public class DateTimeUtil {
    public static String getDateStr(String pattern,Date date){
    SimpleDateFormat df = new SimpleDateFormat(pattern);
    return df.format(date);
    }
    public static Date getDateFromStr(String pattern,String dateStr)throws Exception{
    if(dateStr == null){
    return null;
    }
    SimpleDateFormat df = new SimpleDateFormat(pattern);
    return df.parse(dateStr);
    }
    public static Date addYear(Date date,int amount){
    Calendar cal = new GregorianCalendar();
    cal.setTime(date);
    cal.add(Calendar.YEAR, amount);
    return cal.getTime();
    }
    public static Date addMonth(Date date,int amount){
    Calendar cal = new GregorianCalendar();
    cal.setTime(date);
    cal.add(Calendar.MONTH, amount);
    return cal.getTime();
    }
    public static Date addDate(Date date,int amount){
    Calendar cal = new GregorianCalendar();
    cal.setTime(date);
    cal.add(Calendar.DATE, amount);
    return cal.getTime();
    }
    public static Date addHour(Date date,int amount){
    Calendar cal = new GregorianCalendar();
    cal.setTime(date);
    cal.add(Calendar.HOUR, amount);
    return cal.getTime();
    }
    public static Date addMinute(Date date,int amount){
    Calendar cal = new GregorianCalendar();
    cal.setTime(date);
    cal.add(Calendar.MINUTE, amount);
    return cal.getTime();
    }
    }
  • 相关阅读:
    攻防世界 resver catch-me
    elf.h
    攻防世界 reverse 进阶 notsequence
    攻防世界 reverse 进阶 easyre-153
    攻防世界 reverse 进阶 APK-逆向2
    寒假训练 roarctf_2019_realloc_magic(1/250)
    寒假任务
    Main_arena与non_main_arena
    wdb2018_guess
    :: namespace using作用
  • 原文地址:https://www.cnblogs.com/wangdonghua/p/3320852.html
Copyright © 2011-2022 走看看