日期Date和字串之間轉換

2021-07-02 07:03:43 字數 509 閱讀 8071

date

-- string(格式化)

public final string format(date date)

string -- date(解析)

public date parse(string source)

dateforamt:可以進行日期和字串的格式化和解析,但是由於是抽象類,所以使用具體子類******dateformat。

******dateformat的構造方法:

******dateformat():預設模式

******dateformat(string pattern):給定的模式

這個模式字串該如何寫呢?

通過檢視api,我們就找到了對應的模式

年 y月 m

日 d時 h

分 m秒 s

2023年12月12日 12:12:12

public class dateformatdemo 

}

日期Date和String之間轉換

string轉為date string birthday dateformat fmt new dateformat yyyy mm dd date date fmt.parse birthday date轉為string dateformat dateformat new dateformat y...

js 字串和日期物件之間的轉換

var strtime 2011 04 16 字串日期格式 var date new date date.parse strtime.replace g,轉換成data var month date.getmonth 1 獲取當前月份 測試輸出 var d new date 2018 7 1 con...

python字串與日期之間的轉換

需要用到python中time和datetime包 import time 獲取cts格式 星期 月 日 時分秒 年 time.ctime 結果 wed may 16 15 12 57 2018 字元轉換為tuple time obj date string 2018 11 30 13 53 59 ...