獲取當天的時間 倆個日期進行比較

2021-08-24 17:44:49 字數 673 閱讀 1262

工作中對時間的一些使用:

由於有些時間伺服器返回的是:2018-08-16t18:10:22這些的,可以使用擷取字串的方式進行

/**

* 返回月/日/年

*/public

static string getdate(string str)

stringbuilder stringbuilder = new stringbuilder();

string temp = str.substring(0, str.indexof("t"));

return stringbuilder.tostring();

}

//獲取當天的時間

public

static string getcurrentdate()

//倆個日期進行比較

public

static

intcomparetodate(string date1, string date2) else

if (dt1.gettime() == dt2.gettime()) else

} catch (exception exception)

return -1;

}

日期比較,算上當天的時間

老找不到日期比較函式,用來比較輸入的日期必須比當前日期晚,但是要包括當天。所以就自己寫了乙個最笨的。先檢測日期格式,在拆分比較,當然可以寫在一起的。function strdatetime str d 2 d if r null vard newdate r 1 r 3 1,r 4 return d...

獲取當天是星期幾,計算兩個日期相隔時間

function tformmain.getweek string var date systemtime begin getlocaltime date case date.wdayofweek of 0 result 星期天 1 result 星期一 2 result 星期二 3 result ...

倆個list集合的比較

方法一 方法1,兩層遍歷查詢,遍歷次數為list1.size list2.size 有點蠢 private static listgetdiffrent1 listlist1,listlist2 計時 system.out.println 方法1 耗時 system.currenttimemilli...