5 常用工具類(Date format MD5等)

2021-10-06 12:38:23 字數 3506 閱讀 7103

public

class

dateutil

private

static

final string pattern =

"yyyy-mm-dd hh:mm:ss"

;// private static dateformat dateformat;//充當成員變數

// ******dateformat執行緒不安全 多個執行緒使用了同乙個例項

// 推薦使用: threadlocal管理******dateformat的物件,有且只能儲存乙個物件---> threadlocal會給每個執行緒都會建立乙個物件

//建立threadlocal的例項

private

static

final threadlocal<******dateformat>

thread_local =

newthreadlocal()

};//需要通過thread_local獲得******dateformat的例項 get()

/** * date 轉換成string

* @param date

* @return

*/public

static string dateconverttostr

(date date)

/** * string 轉換成 date

* @param datestr

* @return

*/public

static date strconverttodate

(string datestr)

catch

(parseexception e)

return null;

}}

public

class

calendardemo

}

public

class

instantdemo

}

private

static

final string pattern =

"yyyy-mm-dd hh:mm:ss"

;private

static

final datetimeformatter date_time_formatter = datetimeformatter.

ofpattern

(pattern)

;public

static localdatetime strtolocaldatetime

(string datestr)

public

static string localdatetimetostr

(localdatetime localdatetime)

public

class

localdatetimedemo

,iso resolved to 2020-01-01t12:00

instant now = instant.

now();

//utc

string format = formatter.

format

(now)

; system.out.

println

(format);}

}

public

abstract

class

dateformat

extends

format

public

class

******dateformat

extends

dateformat

常用構造:

******dateformat

(string pattern) 建立指定模式的格式化日期物件

常用方法:

string format

(date date) 將date轉換成string

date parse

(string source) string解析成date

datetimeformatter datetimeformatter = datetimeformatter.

ofpattern

(pattern)

;

public

class

numberformatdemo

private

static

void

demo3()

private

static

void

demo2()

private

static

void

demo1()

}

private

static

void

demo1()

system.out.

println()

;}system.out.

println

("------------------------");

for(

int i =

0; i <

3; i++

) system.out.

println()

;}}

public

class

base64demo

private

static

boolean

login

(string loginpass)

return

true;}

/** * 註冊(儲存使用者資訊 1234(明文)--->加密的之後的資料 密文)

* @param sourcepass

* @return

*/private

static string encoderpass

(string sourcepass)

}

public

class

md5util

public

static string md5

(string source)

catch

(nosuchalgorithmexception e)

return null;

}public

static

void

main

(string[

] args)

}

常用工具類

本講內容 常用工具類 陸續更新 author administrator public static context context public void oncreate public static context getcontext 2 提供所有activity呼叫 基類 author ad...

常用工具類

reflectionutils objectutils public static void main string args 判斷兩個陣列是否相等 system.out.println arrays.equals arr,arr true 列印陣列 string s1 arrays.tostrin...

常用工具類 作業

1.生成10個 10,23 之間的隨機整數 random 類的nextdouble 或nextint 實現public class randomdemo for int i 1 i 10 i 1.以樹狀結構輸出計算機某個指定資料夾下的所有的檔案和子資料夾名稱。public class filedem...