Android 時間轉換工具類

2021-08-31 11:42:40 字數 1142 閱讀 2063

在做聊天頁面的時候,難免遇到要把乙個時間戳轉換為乙個好看的格式,每次都動手寫也太累了,在這裡給大家分享一下我的工具類吧

其中time_year、time_month等 在文字最後貼出來給大家哦。

/**

* 時間轉換工具

*/public class timeutil

/*** 時間轉化為顯示字串

** @param timestamp 單位為秒

*/public static string gettimestr(long timestamp)

calendar.set(calendar.hour_of_day, 0);

calendar.set(calendar.minute, 0);

calendar.set(calendar.second, 0);

calendar.set(calendar.millisecond, 0);

if (calendar.before(inputtime))

calendar.add(calendar.day_of_month,-1);

if (calendar.before(inputtime))elseelse}}

/*** 時間轉化為聊天介面顯示字串

** @param timestamp 單位為秒

*/public static string getchattimestr(long timestamp)

calendar.set(calendar.hour_of_day, 0);

calendar.set(calendar.minute, 0);

calendar.set(calendar.second, 0);

calendar.set(calendar.millisecond, 0);

if (calendar.before(inputtime))

calendar.add(calendar.day_of_month,-1);

if (calendar.before(inputtime))elseelse}}

}

資源檔案引用 存放至 res - values - strings.xml 檔案中即可使用喲

月年

時間格式轉換工具類

時間日期工具類有很多,本文主要說的是將當前日期轉換為當前日期的開始時間,即當前日期的0點0分0秒以及當前日期的結束時間即23點59分59秒 得到當前日期字串開始時間格式 yyyy mm dd 00 00 00 public static date getstarttime string starti...

日期轉換工具類

都是一些比較常用的日期工具類 public final class dateutils 取得ap系統時間。return ap系統時間 public static date getsystemdate 取得ap系統時間,不包括時分秒。return ap系統時間 public static date g...

型別轉換工具類

做專案的時候自己封裝的工具類,方便查詢,放到這裡 public class convertutil inttostring int轉string author lelonta param i return public static string inttostr int i dubtobigdec...