時間 時區 時間格式轉換的工具類

2021-08-08 04:45:20 字數 2121 閱讀 9889

不詩意的女程式猿不是好廚師~

public

class

dateconvertutil

/*** 獲取當前手機對應的系統時區

* */

public

static timezone getphonetimezone()

/*** 以「gmt+8:00」形式返回當前系統對應的時區

*@return

*/public

static string getcurrenttimezonestr()

public

static string creategmtoffsetstring(boolean includegmt,

boolean includeminuteseparator, int offsetmillis)

stringbuilder builder = new stringbuilder(9);

if (includegmt)

if (includeminuteseparator)

return builder.tostring();

}private

static

void

string string = integer.tostring(value);

for (int i = 0; i < count - string.length(); i++)

}/** 格式化日期的標準字串 */

public

final

static string detail_format = "yyyy-mm-dd hh:mm:ss";

// private final static string ******_format="yyyy-mm-dd";

/** * 將日期字串轉換為date物件

*@param date 日期字串,必須為"yyyy-mm-dd hh:mm:ss"

*@param format 格式化字串

*@return 日期字串的date物件表達形式

* */

public

static date parsetodate(string date, string format)

catch(parseexception e)

return dt;

}/**

* 將date----->string

* 將date物件轉換為指定格式的字串

*@param date date物件

*@param //string format 格式化字串

*@return date物件的字串表達形式

* */

public

static string formatdatetostr(date date, string format)

/*** 獲取更改時區後的時間

*@param date 時間

*@param oldzone 舊時區

*@param newzone 新時區

*@return 時間

*/public

static date changetimezone(date date, timezone oldzone, timezone newzone)

return datetmp;

}/**

* 將北京時區的時間轉化為當前系統對應時區的時間

*@param beijingtime

*@param format

*@return

*/public

static string beijingtime2phonetime(string beijingtime,string format)

/*** 將本地系統對應時區的時間轉換為上北京時區對應的時間

*@param phonetime

*@return

*/public

static string phonetime2beijingtime(string phonetime)

}

積累點滴,做好自己~

時間格式轉換工具類

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

mysql 時區 時間轉換 MySQL時間時區轉換

將timestamp轉換為指定時區的時間,如 2018 09 21 11 48 42 select convert tz create time,session.time zone,8 00 from auth user 將timestamp轉換為指定時區的時間,並精確到天數,如 2018 09 2...

時間格式轉換類

時間的字串形式與毫秒形式相互轉換的類。using system namespace myspace 時間的字串形式與毫秒形式相互轉換類。public static class timeformat ms case timingformat.s return string.format s case ...