ISO8601轉換成Date型別

2021-07-11 00:17:39 字數 900 閱讀 4076

2016-12-30t00:00:00.000+08:00,這是個什麼東西我開始的時候也不知道,相信大家也遇見過,這是一種時間格式叫做iso8601。

這種的東西據說有很多好處,但是今天要講的是如何解析這種格式,獲取其中的年、月、日資訊。

gson或者fastjson中存在著iso8601utils類(其中gson是參考fastjson的,噓,我沒說抄),gson的iso8601utils類中,有乙個函式叫做

parse(string date, parseposition pos)(fastjson中的函式叫做parse

(string date)),解析**如下:

date date=iso8601utils.parse(date,newparseposition(0));

calendar calendar=calendar.getinstance();

calendar.settime(date);

intday = calendar.get(calendar.day_of_month);

intmon = calendar.get(calendar.month)+1;//calendar

裡取出來的

month

比實際的月份少

1,所以要加上

intyear = calendar.get(calendar.year);

好的,年月日都獲取到了
大神帶你飛www.stay4it.com

ISO 8601格式時間轉換

param strtime 示例 2020 01 01 23 59 59 return 2020 01 01t15 59 59z 傳入乙個北京時間 字串 返回iso 8601時間 字串 格式出去.public static string getisotime string strtime catch...

String型別時間格式轉換成Date型別

本文對此轉換提供了功能上的實現,沒有對具體方法的詳解。轉換過程中涉及到的主要方法有 dateformate和oracle中的to date方法。先講實現方法 例如 string string 2012 12 12 22 22 22 轉換成 date date 2012 12 12 22 22 22 ...

ISO映象轉換成docker映象

最近開始研究docker,如果想要自己建立個映象,必須從docker hub上面獲取乙個基礎映象來建立 對於我們公司是定製的iso,我就在想有沒有辦法把iso轉換成docker格式,然後上傳到docker hub上作為基礎映象使用。參考文章 0x01 準備階段 首先,在一台虛擬機器中安裝好需要轉換的...