英時間轉換為中文時間

2021-09-27 01:46:11 字數 2419 閱讀 2923

自己建立個類,寫進去可以直接用

public class dateconversion

/** * create date:2010-5-22下午03:40:44 描述:取出日期字串中的年份字串

* * @param str

* 日期字串

* @return

*/public static string getyearstr(string str)

/** * create date:2010-5-22下午03:40:47 描述:取出日期字串中的月份字串

* * @param

* @return

*/public static string getmonthstr(string str)

/** * create date:2010-5-22下午03:32:31 描述:將源字串中的阿拉伯數字格式化為漢字

* * @param sign

* 源字串中的字元

* @return

*/public static char formatdigit(char sign)

/** * create date:2010-5-22下午03:31:51 描述: 獲得月份字串的長度

* * @param str

* 待轉換的源字串

* @param pos1

* 第乙個'-'的位置

* @param pos2

* 第二個'-'的位置

* @return

*/public static int getmidlen(string str, int pos1, int pos2)

/** * create date:2010-5-22下午03:32:17 描述:獲得日期字串的長度

* * @param str

* 待轉換的源字串

* @param pos2

* 第二個'-'的位置

* @return

*/public static int getlastlen(string str, int pos2)

/** * create date:2010-5-22下午03:40:50 描述:取出日期字串中的日字串

* * @param str

* 日期字串

* @return

*/public static string getdaystr(string str)

/** * create date:2010-5-22下午03:32:46 描述:格式化日期

* * @param str

* 源字串中的字元

* @return

*/public static string formatstr(string str)

if (getmidlen(str, pos1, pos2) == 1)

if (getlastlen(str, pos2) == 2) else if (str.charat(7) != '1' && str.charat(8) == '0') else if (str.charat(7) == '1' && str.charat(8) != '0') else

}} else

}if (getmidlen(str, pos1, pos2) == 2)

if (getlastlen(str, pos2) == 2) else if (str.charat(8) != '1' && str.charat(9) == '0') else if (str.charat(8) == '1' && str.charat(9) != '0') else

} else

}} else if (str.charat(5) != '0' && str.charat(6) == '0')

if (getlastlen(str, pos2) == 2) else if (str.charat(8) != '1' && str.charat(9) == '0') else if (str.charat(8) == '1' && str.charat(9) != '0') else

} else

}} else

if (getlastlen(str, pos2) == 2) else if (str.charat(8) != '1' && str.charat(9) == '0') else if (str.charat(8) == '1' && str.charat(9) != '0') else

} else }}

}return sb.tostring();

}public static void main(string args)

C Unix時間戳轉換為時間

在做一些介面的時候,比如返回資料中有乙個時間的屬性,它的值是使用unix時間戳表示的,當我們處理它 儲存到本地或者格式化前台展示 時需要轉換成日期時間,在此就需要根據時間戳轉換為日期時間 注 unix時間戳是當前標準時區時間與1970年1月1日所經歷的總秒數 根據時間戳轉換為當前時間 時間戳 精確到...

JS將時間戳轉換為日期時間格式

最近專案需要在前端將乙個13位的時間戳顯示成日期格式,在網上查了很多都不符合要求,只有乙個是能滿足要求的,在這記錄一下,說不定以後還用的著。13位時間戳改為yyyy mm dd hh mm ss 格式 目標時間戳 1516324500000 將時間戳改為yyyy mm dd hh mm ss fun...

dmesg的時間戳轉換為對應的時間

dmesg 18.204448 bluetooth rfcomm socket layer initialized 18.204452 bluetooth rfcomm ver 1.11dmesg 日誌中的 時間 18.204452 表示的是系統啟動到事件發生的時間差,這個值可以轉換成時間戳 uni...