java常用日期操作

2021-09-02 10:29:06 字數 898 閱讀 7851

/**

* 根據開始日期 ,需要的工作日天數 ,計算工作截止日期,並返回截止日期

* @param startdate 開始日期

* @param workday 工作日天數(周一到周五)

* @return date型別

* @createtime 2014-2-14

* @author sunqinbo

*/public static date getworkday(date startdate, int workday)

}******dateformat df = new ******dateformat("yyyy-mm-dd hh:mm:ss");

system.out.println(df.format(c1.gettime()) + " " + getweekofdate(c1.gettime()));

return c1.gettime();}

/** * 根據日期,獲取星期幾

* @param dt

* @return string型別

* @createtime 2014-2-14

* @author sunqinbo

*/public static string getweekofdate(date dt) ;

calendar cal = calendar.getinstance();

cal.settime(dt);

int w = cal.get(calendar.day_of_week) - 1;

if (w < 0) w = 0;

return weekdays[w];}

public static void main(string args)

}

java 日期操作全集

public class timetest 得到二個日期間的間隔天數 public static string gettwoday string sj1,string sj2 catch exception e return day 根據乙個日期,返回是星期幾的字串 param sdate retu...

Java日期加減操作

date date new date 起始時間 dateformat sdf new dateformat yyyymmdd hhmmss 按照指定格式 格式化日期 string str sdf.format date 格式化起始日期 date dt sdf.parse str 解析字串的文字,生成...

Mysql日期常用操作

timestamp時間戳格式 timestamp格式的使用期限是 1970 1 1 到 2038年 timestamp格式的字段,可以在行記錄更新時,自動更新時間.表設計如下 執行update t user set birthday 1980 2 12 17 09 14 where user id ...