時間格式轉換(Date String)

2021-09-19 19:08:52 字數 1617 閱讀 7338

/**

* 傳入具體一天,返回具體日期減少一天

* * @throws parseexception

*/public static string subday(string date) catch (exception e)

final calendar rightnow = calendar.getinstance();

rightnow.settime(dt);

rightnow.add(calendar.date, -1);

final date dt1 = rightnow.gettime();

final string restr = sdf.format(dt1);

return restr;

} /**

* @param dateinms

* 傳入的時間long值

* @param days

* 天數 如 -1 +1

* @return

*/public static string getdatebylong(long dateinms, int days)

/*** 時間(yyyy-mm-dd hh:mm:ss):string格式轉date格式

*/public static date parsetimeformattodate(string date) catch (exception e)

return time;

} /**

* 時間(yyyy-mm-dd hh:mm:ss):date格式轉string格式

*/public static string parsetimetostring(date date)

/*** 時間(yyyy-mm-dd):string格式轉date格式

*/public static date parsetimeformattodaydate(string date) catch (exception e)

return time;

} /**

* 時間(yyyy-mm-dd):date格式轉string格式

*/public static string parsetimeformattodaydate(date date) catch (exception e)

return time;

} /**

* 時間(yyyy-mm):date格式轉string格式

*/public static string parsetimeformattomonthdate(date date) catch (exception e)

return time;

} /**

* 獲取:昨天22:00 今天22:00

* * @return

*/public static mapgetday()

/*** 時間(yyyy-mm):string格式轉date格式

*/public static date parsetimeformattomonthdate(string date) catch (exception e)

return time;

}

時間格式轉換

一 在mysql中完成 這種方式在mysql查詢語句中轉換,優點是不占用php解析器的解析時間,速度快,缺點是只能用在資料庫查詢中,有侷限性。1.unix時間戳轉換為日期用函式 from unixtime 一般形式 select from unixtime 1156219870 2.日期轉換為uni...

時間格式轉換

dateformat函式語法 g 年代標誌符 y 年m 月 d 日h 時 在上午或下午 1 12 h 時 在一天中 0 23 m 分s 秒 s 毫秒 e 星期 d 一年中的第幾天 f 一月中第幾個星期幾 w 一年中第幾個星期 w 一月中第幾個星期 a 上午 下午 標記符 k 時 在一天中 1 24 ...

時間格式轉換

24 小時制的時間格式為 hh mm 如 05 20 而 12 小時制的時間格式為 h mm am pm 如 5 20 am 24 小時製到 12 小時制的對應關係如下 0 時 12 時 am 1 11 時 1 11 時 am 12 時 12 時 pm 13 23 時 1 11 時 pm 例如 00...