時間按指定格式轉換

2021-10-01 21:18:17 字數 4546 閱讀 6564

推薦閱讀:

一。把秒數轉換成 00:00:00 大於一天顯示 1天2時

local function

second2dhms

(second)

if second <=

0 then

return0,

0,0,

0 end

local d = math.

floor

(second /

86400

) second = second - d *

86400

local h = math.

floor

(second /

3600

) second = second - h *

3600

local m = math.

floor

(second /60)

second = second - m *

60 local s = second

return d, h, m, s

endlocal function

gettimestrday

(second)

local _d, _h, _m, _s =

second2dhms

(second)

local timedata =

""if _d >

0 then

timedata = _d.

."天"

.._h.

."小時"

else

if _h <

10 then

_h =

"0".

._h end

if _m <

10 then

_m =

"0".

._m

endif _s <

10 then

_s =

"0".

._s end

timedata = _h.

.":"

.._m.

.":"

.._s

endreturn timedata

end

二。把秒數轉換成 00:00:00
-- 把秒數轉換成 00:00

:00

local function

gettimestr

(second)

local hour = math.

floor

(second /

3600

) local min = math.

floor

(second %

3600/60

) local sec = second %

60return string.

format

("%02d:%02d:%02d"

, hour, min, sec)

end

三。把秒數轉換成 00:00:00
local function

gettimestr1

(second)

local hour = math.

floor

(second /

3600

) local min = math.

floor

(second %

3600/60

) local sec = second %

60return string.

format

("%02d:%02d:%02d"

, hour, min, sec)

end

四。把秒數轉換成 分鐘:秒數 00:00
local function

gettimestr2

(second)

local min = math.

floor

(second/60)

local sec = second %

60return string.

format

("%02d:%02d"

, min, sec)

end

五。把秒數轉換成 小時:分鐘 00:00
local function

gettimestr3

(second)

local hour = math.

floor

(second /

3600

) local min = math.

floor

(second %

3600/60

)return string.

format

("%02d:%02d"

, hour, min)

end

六。把秒數轉成 x小時x分鐘
local function

gettimestr4

(second)

local hour = math.

floor

(second /

3600

) local min = math.

floor

(second %

3600/60

)if hour >

0 then

return string.

format

("%d小時%d分鐘"

, hour, min)

endreturn string.

format

("%d分鐘"

, min)

end

七。把秒數轉成 x小時x分鐘x秒
local function

gettimestr5

(second)

local hour = math.

floor

(second /

3600

) local min = math.

floor

(second %

3600/60

) local sec = second %

60if hour >

0 then

return string.

format

("%d小時%d分鐘%d秒"

, hour, min, sec)

endreturn string.

format

("%d分鐘%d秒"

, min, sec)

end

八。把秒數轉成 x天x小時x分鐘x秒
local function

gettimestr6

(second)

local day = math.

floor

(second /

86400

) local hour = math.

floor

(second %

86400

/3600

) local min = math.

floor

(second %

3600/60

) local sec = second %

60return string.

format

("%d天%d小時%d分鐘%d秒"

, day, hour, min, sec)

end

九。把秒數轉成 x天x小時
local function

gettimestr7

(second)

local day = math.

floor

(second /

86400

) local hour = math.

floor

(second %

86400

/3600

)return string.

format

("%d天%d小時"

, day, hour)

end

十。把秒數轉成 x天
local function

gettimestr8

(second)

local day = math.

floor

(second /

86400

) local hour = math.

floor

(second %

86400

/3600

)return string.

format

("%d天"

, day)

end

時間按指定格式轉換

推薦閱讀 一。把秒數轉換成 00 00 00 大於一天顯示 1天2時local function second2dhms second if second 0 then return 0,0,0,0 endlocal d math.floor second 86400 second second d...

JavaScript按指定格式輸出時間

按所給的時間格式輸出指定的時間 格式說明 對於 2014.09.05 13 14 20 yyyy 年份,2014 yy 年份,14 mm 月份,補滿兩位,09 m 月份,9 dd 日期,補滿兩位,05 d 日期,5 hh 24制小時,補滿兩位,13 h 24制小時,13 hh 12制小時,補滿兩位,...

mysql 時間戳按指定格式(Y m d)取出

之前做採集指令碼,把採集的時間按unix時間戳的形式取出 那麼在寫sql語句的時候,需要按時間查詢相應的記錄,頁面傳進來的 time 是 2014 01 之類的字串,那麼怎麼寫sql呢 sql.and from unixtime time,y m time.這樣能取出資料庫中 time 相對應的記錄...