How do I get the current month as an integer, and as a string?
如何将当前月份作为整数和字符串?
So for this month, I would want "7" and the string "July".
因此,对于这个月,我想要“7”和字符串“July”。
Is there an easy way to do this without a lot of string parsing and a lookup list for month names?
有没有很多字符串解析和月份名称查找列表,有一个简单的方法吗?
3 个解决方案
#1
What you need is the clock
command.
你需要的是clock命令。
http://www.tcl.tk/man/tcl8.5/TclCmd/clock.htm#M7
To get the textual representation of the month, use:
要获取月份的文本表示,请使用:
clock format [clock seconds] -format %B
And the numeric representation:
和数字表示:
clock format [clock seconds] -format %N
#2
My company's Tcl is at version 8.4 and the %N format does not work. I guess it is a Tcl 8.5 feature. To get around that issue:
我公司的Tcl版本为8.4,%N格式不起作用。我想这是一个Tcl 8.5功能。要解决这个问题:
set monthNumber [string trimleft [clock format [clock seconds] -format %m] 0]
#3
In tcl 8.4 you can use %h and it will return the abbreviated month name ( eg. Oct )
在tcl 8.4中,您可以使用%h,它将返回缩写的月份名称(例如,Oct)
#1
What you need is the clock
command.
你需要的是clock命令。
http://www.tcl.tk/man/tcl8.5/TclCmd/clock.htm#M7
To get the textual representation of the month, use:
要获取月份的文本表示,请使用:
clock format [clock seconds] -format %B
And the numeric representation:
和数字表示:
clock format [clock seconds] -format %N
#2
My company's Tcl is at version 8.4 and the %N format does not work. I guess it is a Tcl 8.5 feature. To get around that issue:
我公司的Tcl版本为8.4,%N格式不起作用。我想这是一个Tcl 8.5功能。要解决这个问题:
set monthNumber [string trimleft [clock format [clock seconds] -format %m] 0]
#3
In tcl 8.4 you can use %h and it will return the abbreviated month name ( eg. Oct )
在tcl 8.4中,您可以使用%h,它将返回缩写的月份名称(例如,Oct)