我想要做的是在日期中添加"th"或"rd",即Lua中的第27,第30等.
我确信最好使用循环来完成这项任务,这可能吗?
我试着浏览/学习并为自己尝试,但我一遍又一遍地失败了.
MeasureDate和MeterDate是添加日期的日期.
我已粘贴下面的代码.
;----------RainMeter [Rainmeter] Update=#UpdateRateAmount# ;-------- Lua Script [LuaScript] Measure=Script ScriptFile=#skinspath#/MyScript.lua ;---------Variables [Variables] @include="#skinspath#/SkinVariables.inc" [ClockStyle] FontFace=#Font# FontColor=#ClockFontColor# AntiAlias=1 FontSize=120 StringAlign=Left StringEffect=Border FontEffectColor=#ClockFontEffectColor# ;---- Minute Variables [MinuteStyle] FontFace=#Font# FontColor=#MinuteFontColor# AntiAlias=1 FontSize=120 StringAlign=Left StringEffect=Border FontEffectColor=#MinuteFontEffectColor# [FontStyle] FontFace=#Font# FontColor=#FontColor# AntiAlias=1 StringAlign=Left StringEffect=Border FontEffectColor=#FontEffectColor# ;--------Date ;---------Clock [MeasureDate] Measure=Time Format=%d UpdateDivider=#UpdateDividerAmount# [MeasureHour] Measure=Time Format=%#ClockMode# UpdateDivider=#UpdateDividerAmount# [MeasureMinute] Measure=Time Format=%M UpdateDivider=#UpdateDividerAmount# [MeasureWeekday] Measure=Time Format=%A Substitute="Sunday":"SUN","Monday":"MON","Tuesday":"TUES","Wednesday":"WED","Thursday":"THURS","Friday":"FRI","Saturday":"SAT" UpdateDivider=#UpdateDividerAmount# [MeasureMonth] Measure=Time Format=%b UpdateDivider=#UpdateDividerAmount# StringCase=Upper Substitute="Jan":"JAN.","Feb":"FEB.","Mar":"MAR.","Apr":"APR.","Jun":"JUN.","Jul":"JUL.","Aug":"AUG.","Sep":"SEP.","Oct":"OCT.","Nov":"NOV.","Dec":"DEC." FontFace=Courier [MeasureYear] Measure=Time Format=%Y UpdateDivider=#UpdateDividerAmount# [I] Measure=Time Format=%p UpdateDivider=#UpdateDividerAmount# [MeterHour] Meter=String MeasureName=MeasureHour MeterStyle=ClockStyle X=9r Y=-9r Text='%1' [BetweenMinHr] Meter=String FontSize=45 MeterStyle=MinuteStyle Text=: x=200r y=60r [MeterMinute] Meter=String MeasureName=MeasureMinute MeterStyle=MinuteStyle X=0r Y=-63r Text='%1' [MeterWeekday] Meter=String MeasureName=MeasureWeekday MeterStyle=FontStyle StringAlign=Right FontSize=30 StringCase=Upper X=16r Y=153r Text='%1' [MeterDate] Meter=String MeasureName=MeasureDate MeterStyle=FontStyle StringAlign=Center FontSize=120 X=70r Y=-10r StringEffect=BORDER Text='%1' [MeterMonth] Meter=String MeasureName=MeasureMonth MeterStyle=FontStyle StringAlign=Left FontSize=40 X=-200r Y=43r Text='%1' [MeterAm/Pm] Meter=String MeasureName=#ClockMode# MeterStyle=FontStyle StringAlign=Left FontSize=35 X=310r Y=-75r [MeterBox] Meter=Image SolidColor=2,1,1,0 X=-380r Y=-240r H=280 W=450
SkinVariables.inc
[变量]
Font=Century Gothic ;---- Clock ;For a 12 hour clock mode, put 'I' ;For a 24 hour clock mode, put 'H' ClockMode=I FontColor=35,35,35,255 FontEffectColor=255,255,255,150 ClockFontColor=35,35,35,255 ClockFontEffectColor=242,242,242,100 MinuteFontColor=255,255,255,255 MinuteEffectColor=0,0,0,128 MinuteFontEffectColor=0,0,0,128
Josh.. 6
您可以使用以下功能轻松地将数字更改为序数:
function ordinal_numbers(n) local ordinal, digit = {"st", "nd", "rd"}, string.sub(n, -1) if tonumber(digit) > 0 and tonumber(digit) <= 3 and string.sub(n,-2) ~= 11 and string.sub(n,-2) ~= 12 and string.sub(n,-2) ~= 13 then return n .. ordinal[tonumber(digit)] else return n .. "th" end end
它可能会变得更好更清洁,但它适用于您的目的.
您可以使用以下功能轻松地将数字更改为序数:
function ordinal_numbers(n) local ordinal, digit = {"st", "nd", "rd"}, string.sub(n, -1) if tonumber(digit) > 0 and tonumber(digit) <= 3 and string.sub(n,-2) ~= 11 and string.sub(n,-2) ~= 12 and string.sub(n,-2) ~= 13 then return n .. ordinal[tonumber(digit)] else return n .. "th" end end
它可能会变得更好更清洁,但它适用于您的目的.