sql的date和string轉換

2021-09-13 21:18:55 字數 2217 閱讀 1168

涉及的函式

date_format(date, format) 函式,mysql日期格式化函式date_format()

unix_timestamp() 函式

str_to_date(str, format) 函式

from_unixtime(unix_timestamp, format) 函式,mysql時間戳格式化函式from_unixtime

時間轉字串

selectdate_format(now(),'%y-%m-%d');

#結果:2016-01-05

時間轉時間戳

selectunix_timestamp(now());

#結果:1452001082

字串轉時間

selectstr_to_date('2016-01-02','%y-%m-%d %h');

#結果:2016-01-02 00:00:00

字串轉時間戳

selectunix_timestamp('2016-01-02');

#結果:1451664000

時間戳轉時間

selectfrom_unixtime(1451997924);

#結果:2016-01-05 20:45:24

時間戳轉字串

selectfrom_unixtime(1451997924,'%y-%d');

//結果:2016-01-05 20:45:24

附表mysql日期格式化(format)取值範圍。值含義

秒%s、%s

兩位數字形式的秒( 00,01, ..., 59)

分%i、%i

兩位數字形式的分( 00,01, ..., 59)

小時 %h

24小時制,兩位數形式小時(00,01, ...,23)

%h12小時制,兩位數形式小時(00,01, ...,12)

%k24小時制,數形式小時(0,1, ...,23)

%l12小時制,數形式小時(0,1, ...,12)

%t24小時制,時間形式(hh:mm:ss)

%r12小時制,時間形式(hh:mm:ss am 或 pm)

%p am上午或pm下午 

周 %w

一周中每一天的名稱(sunday,monday, ...,saturday)

%a一周中每一天名稱的縮寫(sun,mon, ...,sat) 

%w 以數字形式標識周(0=sunday,1=monday, ...,6=saturday) 

%u數字表示週數,星期天為週中第一天

%u數字表示週數,星期一為週中第一天

天%d 

兩位數字表示月中天數(01,02, ...,31)

%e 數字表示月中天數(1,2, ...,31)

%d英文本尾表示月中天數(1st,2nd,3rd ...) 

%j以三位數字表示年中天數(001,002, ...,366) 

月%m 

英文月名(january,february, ...,december) 

%b 英文縮寫月名(jan,feb, ...,dec) 

%m 兩位數字表示月份(01,02, ...,12)

%c 數字表示月份(1,2, ...,12) 

年%y 

四位數字表示的年份(2015,2016...)

%y 兩位數字表示的年份(15,16...)

文字輸出 

%文字 

直接輸出文字內容

springmvc 用dateconvert最終解決問題.

posted @

2019-03-27 13:31

a點點圈圈a 閱讀(

...)

編輯收藏

sql的date和string轉換

涉及的函式 date format date,format 函式,mysql日期格式化函式date format unix timestamp 函式 str to date str,format 函式 from unixtime unix timestamp,format 函式,mysql時間戳格式...

String 和 Date 的相互轉換

dateformat 是string和date相互轉換的主要使用類,例如 date轉string public static void main string args 結果如下 string轉date public static void main string args throws parse...

iOS中date和string的轉換

產自mknetworkkit中的nsdate rfc1123 分類中總共兩個方法,分別是 nsdate datefromrfc1123 nsstring value 將字串轉為時間型別 nsstring rfc1123string 將時間型別轉為字串 這裡面有個rcf1123時間格式的字串作為轉換前...