date 日期工具類

2021-07-27 09:36:26 字數 2116 閱讀 4352

/**

* 兩個日期相減獲得月份

* @param startcal

* @param endcal

* @return

* @throws parseexception

*/ public static int twodatagetmonth(string startcal,string endcal) throws parseexception

if (year>0)

if (month < 0)

return month;

}/**

* date日期轉換為timestamp

* @param time

* @return

* @throws parseexception

*/ public static timestamp formattimestamp(date time) throws parseexception/**

* yyyy-mm-dd hh:mm:ss

* @param time

* @return

* @throws parseexception

*/ public static timestamp formattimestamp(string time) throws parseexception/**

* 幾天後

* @param disday

* @return

*/ public static timestamp gettimestamp(int disday)

/**

* 判斷日期是否過期

* @author yulong

* @description

* @date 2012-8-25

* @param date 生產日期

* @param minute 分鐘

* @return

*/ public static boolean datei***pire(date date,int minute)

return true;

}/**

* 增加或減少數分鐘

* @author yulong

* @description

* @date 2012-8-25

* @param date

* @param n

* @return

*/ public static date addminute(date date, int n)

/**

* 增加或減少數小時

* @author yulong

* @description

* @date 2012-8-25

* @param date

* @param n

* @return

*/ public static date addhour(date date, int n)

/* *計算出多久之前 如:1小時前 乙個月前

* */

public class pasttime

public static string format(date date)

if (delta < 45l * one_minute)

if (delta < 24l * one_hour)

if (delta < 48l * one_hour)

if (delta < 30l * one_day)

if (delta < 12l * 4l * one_week) else

}private static long toseconds(long date)

private static long tominutes(long date)

private static long tohours(long date)

private static long todays(long date)

private static long tomonths(long date)

private static long toyears(long date)

Date類,實現日期類

1 概述 類 date 表示特定的瞬間,精確到毫秒。2 構造方法 public date public date long date 把乙個long型別的毫秒值轉換成乙個日期物件 3 成員方法 public long gettime 獲取乙個日期物件物件毫秒值 public void settime...

時間date工具類

public class datetool public static date getnow public static string getdate public static string getym public static string getdatetime 獲得當前月的上一 publ...

Date 時間工具類

問題引出 我們每次用到date時間這個類的時候,時間物件轉化為指定的字串,或者把字串轉化為時間物件,等等相對來說會比較麻煩,下面這個時間工具類提供了各種轉化方法,呼叫相應方法就能得到你想要的答案 public class dateutils return parsestring2date dates...