計算天數差 常用日期函式

2022-09-05 17:15:06 字數 3811 閱讀 1243

long days = mss / ( 60 * 60 * 24);

long hours = (3601 % ( 60 * 60 * 24)) / (60 * 60);

long minutes = (3601 % ( 60 * 60)) /60;

long seconds = 3601 % 60;

system.out.println(hours+"\t"+minutes+"\t"+seconds);1 0 1

******dateformat

dateutil

dateformatutil

localdatetime

calendar

localdate          

system.out.println(localdatetime.of(localdate.now(), localtime.min).format(datetimeformatter.ofpattern("yyyy-mm-dd hh:mm:ss")));

system.out.println(localdatetime.of(localdate.now(), localtime.max).format(datetimeformatter.ofpattern("yyyy-mm-dd hh:mm:ss")));

system.out.println(localdatetime.of(localdate.now(), localtime.noon).format(datetimeformatter.ofpattern("yyyy-mm-dd hh:mm:ss")));

2021-12-08 00:00:00

2021-12-08 23:59:59

2021-12-08 12:00:00

localdate date****** = localdate.parse("20180729", datetimeformatter.basic_iso_date);

localdate localdate = localdate.parse("19570323", datetimeformatter.ofpattern("yyyymmdd"));

system.out.println(localdate);

public static double datediffdays(string starttime, string endtime,

string format, string str) else

} catch (parseexception e)

return 0;

}//獲取時間差把判斷換成這部分

double h= double.valueof((hour - day * 24)+"."+(min - day * 24 * 60));

return new decimalformat("0.00").format(h);

/**/計算一天的時間差 只能是一天的不然錯

public static string gethours(string end1,string begin1)throws parseexception

string min = string.valueof(m);

boolean mi = min.contains("-");

if(mi==true)

string result=new decimalformat("0.00").format(double.valueof(hour+"."+min));

return result;

}——------------------------------------js

function getremaindertime (startdate,enddate)else

}/**

* 獲取日期之間的天數

* @param d1

* @param d2

* @return

*/public int getdaysbetween(calendar d1, calendar d2)

int days = d2.get(calendar.day_of_year)

- d1.get(calendar.day_of_year);

int y2 = d2.get(calendar.year);

if (d1.get(calendar.year) != y2) while (d1.get(calendar.year) != y2);

}return days;

}/**

* 獲取工作日

* @param d1

* @param d2

* @return

*/public int getworkingday(calendar d1, calendar d2)

// int betweendays = getdaysbetween(d1, d2);

// int charge_date = 0;

int charge_start_date = 0;// 開始日期的日期偏移量

int charge_end_date = 0;// 結束日期的日期偏移量

// 日期不在同乙個日期內

int stmp;

int etmp;

stmp = 7 - d1.get(calendar.day_of_week);

etmp = 7 - d2.get(calendar.day_of_week);

if (stmp != 0 && stmp != 6)

if (etmp != 0 && etmp != 6)

// }

result = (getdaysbetween(this.getnextmonday(d1), this.getnextmonday(d2)) / 7)

* 5 + charge_start_date - charge_end_date;

// system.out.println("charge_start_date>" + charge_start_date);

// system.out.println("charge_end_date>" + charge_end_date);

// system.out.println("between day is-->" + betweendays);

return result;

}/**

* 獲取中文日期

* @param date

* @return

*/public string getchineseweek(calendar date) ;

int dayofweek = date.get(calendar.day_of_week);

// system.out.println(daynames[dayofweek - 1]);

return daynames[dayofweek - 1];

}/**

* 獲得日期的下乙個星期一的日期

* @param date

* @return

*/public calendar getnextmonday(calendar date) while (result.get(calendar.day_of_week) != 2);

return result;

}/**

* 獲取休息日

營銷日期天數計算

1.將上一行的enddate放置在下一行,並格式化時間 格式化為yyyy mm dd 方便後期求時間差 select brand,from unixtime unix timestamp startdate,yyyymmdd yyyy mm dd startdate,from unixtime un...

python 日期相減得天數差

import datetime def straight minus date1 date2 flag 3 while 1 date1 input please input the fisrt date like,format like 20180808 n t date2 input please...

關於日期天數計算的幾個函式

關於日期天數計算的 幾個函式!今天早上突然要用到乙個計算某月有多少天的函式,翻了半天沒找到系統自帶著中函式,於是動手寫了乙個,如下 返回某個月有多少天functionhowmonthday parameterscdate localdaysasinteger,yearsasinteger if ty...