時間格式化處理工具類

2021-10-03 10:32:46 字數 1331 閱讀 6794

/**

* 時間格式化

* 引數:

* time:時間

* type:

* 0 -> 今天10:20 昨天10:20 2019.01.21 10:29

* 1 -> 10:20 昨天10:20 2019.01.21 10:29

* 2 -> 2019.01.21 10:29

* 3 -> 2019.01.21

* 4 -> 10:29

* 5 -> 今天10:20 2019.01.21 10:29

*/private fun commontime(time: long, type: int = 0): string

3 ->

4 ->

5 -> $hour:$minute"}}

return "$year.$month.$day $hour:$minute"

}6 -> 月"

}7 -> 年$月"

}else -> $hour:$minute"

}1 ->

-1 ->

}return "$year.$month.$day $hour:$minute"}}

}/**

* date2比date1多的天數

* @param time1

* @param time2

* @return

*/fun differentdays(time1: long, time2: long): int else

}return timedistance + (day2 - day1)

} else

}/**

* 是否為今年

*/fun istoyear(time: long): boolean

return false

}/**

* 秒轉換為分

* math.ceil()執行向上捨入

* math.floor()執行向下捨入

* math.round()四捨五入

*/private fun changes2m(second: long): string

/*** 時間格式轉long

* 2018-08-20 14:53:37時間格式 -> 時間戳

*/@suppresslint("******dateformat")

@jvmstatic

fun timestringtolong(time: string?): long catch (e: exception)

return date().time

}

時間格式處理,工具類。

1 記錄乙個時間的工具類,用以獲取某一天的日期 注釋在裡面寫的很清楚,我就不多說了。說兩個方法 dateformat 這個方法用於將時間的字串格式,轉化成date格式。也可以將date格式轉化成字串格式其實在這個方法中真正操作時間的是calendar public static string get...

Java日期時間格式化處理

date date new date string str string.format tc date 常用如下 te 乙個月中的某一天,如2 tb 指定言環境的月份簡稱,如feb 英文 二月 中文 tb 指定語言環境的月份全稱,如february 英文 二月 中文 ta 指定語言環境的星期全稱,如...

java時間處理工具類

public class timehelper 預設當前時間 精確到秒 return 當前時間 public static string getnow 通過指定的格式獲取當前時間字串 param format 日期字串格式 return 當前時間字串 public static string get...